Subzero: More asm-verbose fixes.

It turns out that code deleted in 9a05aea88a8d9484d5f0ea1f2eabf52ee5a3647f actually had a legitimate purpose, so it is added back, this time with more extensive comments justifying it.

Also, takes the instruction's IsDestNonKillable flag into account when updating the live register usage count (along with extra comments on why that is necessary).

Furthermore, removes an unnecessary assert that otherwise fails when --asm-verbose is used with --filetype=iasm or --filetype-obj.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/1158113002
diff --git a/src/IceCfg.cpp b/src/IceCfg.cpp
index 5b5c32b..50aa5ee 100644
--- a/src/IceCfg.cpp
+++ b/src/IceCfg.cpp
@@ -495,7 +495,6 @@
 
 void Cfg::emitIAS() {
   TimerMarker T(TimerStack::TT_emit, this);
-  assert(!Ctx->getFlags().getDecorateAsm());
   // The emitIAS() routines emit into the internal assembler buffer,
   // so there's no need to lock the streams.
   for (CfgNode *Node : Nodes)
diff --git a/src/IceCfgNode.cpp b/src/IceCfgNode.cpp
index 19c5d22..f69d3c1 100644
--- a/src/IceCfgNode.cpp
+++ b/src/IceCfgNode.cpp
@@ -828,21 +828,26 @@
     return;
   bool First = true;
   Variable *Dest = Instr->getDest();
-  if (Dest && Dest->hasReg())
+  // Normally we increment the live count for the dest register.  But
+  // we shouldn't if the instruction's IsDestNonKillable flag is set,
+  // because this means that the target lowering created this
+  // instruction as a non-SSA assignment; i.e., a different, previous
+  // instruction started the dest variable's live range.
+  if (!Instr->isDestNonKillable() && Dest && Dest->hasReg())
     ++LiveRegCount[Dest->getRegNum()];
   for (SizeT I = 0; I < Instr->getSrcSize(); ++I) {
     Operand *Src = Instr->getSrc(I);
     SizeT NumVars = Src->getNumVars();
     for (SizeT J = 0; J < NumVars; ++J) {
       const Variable *Var = Src->getVar(J);
-      bool ShouldEmit = Instr->isLastUse(Var);
-      if (Var->hasReg()) {
+      bool ShouldReport = Instr->isLastUse(Var);
+      if (ShouldReport && Var->hasReg()) {
         // Don't report end of live range until the live count reaches 0.
         SizeT NewCount = --LiveRegCount[Var->getRegNum()];
         if (NewCount)
-          ShouldEmit = false;
+          ShouldReport = false;
       }
-      if (ShouldEmit) {
+      if (ShouldReport) {
         if (First)
           Str << " \t# END=";
         else
@@ -885,6 +890,10 @@
   bool DecorateAsm =
       Liveness && Func->getContext()->getFlags().getDecorateAsm();
   Str << getAsmName() << ":\n";
+  // LiveRegCount keeps track of the number of currently live
+  // variables that each register is assigned to.  Normally that would
+  // be only 0 or 1, but the register allocator's AllowOverlap
+  // inference allows it to be greater than 1 for short periods.
   std::vector<SizeT> LiveRegCount(Func->getTarget()->getNumRegisters());
   if (DecorateAsm) {
     const bool IsLiveIn = true;
@@ -900,8 +909,21 @@
   for (const Inst &I : Insts) {
     if (I.isDeleted())
       continue;
-    if (I.isRedundantAssign())
+    if (I.isRedundantAssign()) {
+      // Usually, redundant assignments end the live range of the src
+      // variable and begin the live range of the dest variable, with
+      // no net effect on the liveness of their register.  However, if
+      // the register allocator infers the AllowOverlap condition,
+      // then this may be a redundant assignment that does not end the
+      // src variable's live range, in which case the active variable
+      // count for that register needs to be bumped.  That normally
+      // would have happened as part of emitLiveRangesEnded(), but
+      // that isn't called for redundant assignments.
+      Variable *Dest = I.getDest();
+      if (DecorateAsm && Dest->hasReg() && !I.isLastUse(I.getSrc(0)))
+        ++LiveRegCount[Dest->getRegNum()];
       continue;
+    }
     I.emit(Func);
     if (DecorateAsm)
       emitLiveRangesEnded(Str, Func, &I, LiveRegCount);