]> granicus.if.org Git - llvm/commitdiff
[Hexagon] Tie implicit uses to defs in predicated instructions
authorKrzysztof Parzyszek <kparzysz@codeaurora.org>
Wed, 9 Aug 2017 19:58:00 +0000 (19:58 +0000)
committerKrzysztof Parzyszek <kparzysz@codeaurora.org>
Wed, 9 Aug 2017 19:58:00 +0000 (19:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310514 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Hexagon/HexagonExpandCondsets.cpp

index bacb4b1a19218361fa6881022a37e407d342038c..b37a1e716309d299c5e867f70b2f780da752bdec 100644 (file)
@@ -488,16 +488,32 @@ void HexagonExpandCondsets::updateDeadsInRange(unsigned Reg, LaneBitmask LM,
     if (!HII->isPredicated(*DefI))
       continue;
     // Construct the set of all necessary implicit uses, based on the def
-    // operands in the instruction.
-    std::set<RegisterRef> ImpUses;
-    for (auto &Op : DefI->operands())
-      if (Op.isReg() && Op.isDef() && DefRegs.count(Op))
-        ImpUses.insert(Op);
+    // operands in the instruction. We need to tie the implicit uses to
+    // the corresponding defs.
+    std::map<RegisterRef,unsigned> ImpUses;
+    for (unsigned i = 0, e = DefI->getNumOperands(); i != e; ++i) {
+      MachineOperand &Op = DefI->getOperand(i);
+      if (!Op.isReg() || !DefRegs.count(Op))
+        continue;
+      if (Op.isDef()) {
+        ImpUses.insert({Op, i});
+      } else {
+        // This function can be called for the same register with different
+        // lane masks. If the def in this instruction was for the whole
+        // register, we can get here more than once. Avoid adding multiple
+        // implicit uses (or adding an implicit use when an explicit one is
+        // present).
+        ImpUses.erase(Op);
+      }
+    }
     if (ImpUses.empty())
       continue;
     MachineFunction &MF = *DefI->getParent()->getParent();
-    for (RegisterRef R : ImpUses)
+    for (std::pair<RegisterRef, unsigned> P : ImpUses) {
+      RegisterRef R = P.first;
       MachineInstrBuilder(MF, DefI).addReg(R.Reg, RegState::Implicit, R.Sub);
+      DefI->tieOperands(P.second, DefI->getNumOperands()-1);
+    }
   }
 }