Browse Source

Ensure REG_SEQUENCE source operands are unique.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103449 91177308-0d34-0410-b5e6-96231b3b80d8
Evan Cheng 15 years ago
parent
commit
0bcccac504
1 changed files with 19 additions and 0 deletions
  1. 19 0
      lib/CodeGen/TwoAddressInstructionPass.cpp

+ 19 - 0
lib/CodeGen/TwoAddressInstructionPass.cpp

@@ -1164,6 +1164,8 @@ bool TwoAddressInstructionPass::EliminateRegSequences() {
       DEBUG(dbgs() << "Illegal REG_SEQUENCE instruction:" << *MI);
       llvm_unreachable(0);
     }
+
+    SmallSet<unsigned, 4> Seen;
     for (unsigned i = 1, e = MI->getNumOperands(); i < e; i += 2) {
       unsigned SrcReg = MI->getOperand(i).getReg();
       if (MI->getOperand(i).getSubReg() ||
@@ -1171,6 +1173,23 @@ bool TwoAddressInstructionPass::EliminateRegSequences() {
         DEBUG(dbgs() << "Illegal REG_SEQUENCE instruction:" << *MI);
         llvm_unreachable(0);
       }
+
+      if (!Seen.insert(SrcReg)) {
+        // REG_SEQUENCE cannot have duplicated operands. Add a copy.
+        const TargetRegisterClass *RC = MRI->getRegClass(SrcReg);
+        unsigned NewReg = MRI->createVirtualRegister(RC);
+        bool Emitted =
+          TII->copyRegToReg(*MI->getParent(), MI, NewReg, SrcReg, RC, RC,
+                            MI->getDebugLoc());
+        (void)Emitted;
+        assert(Emitted && "Unable to issue a copy instruction!\n");
+        MI->getOperand(i).setReg(NewReg);
+        MI->getOperand(i).setIsKill();
+      }
+    }
+
+    for (unsigned i = 1, e = MI->getNumOperands(); i < e; i += 2) {
+      unsigned SrcReg = MI->getOperand(i).getReg();
       unsigned SrcIdx = MI->getOperand(i+1).getImm();
       UpdateRegSequenceSrcs(SrcReg, DstReg, SrcIdx, MRI);
     }