[llvm] r182925 - Fix rematerialization into physical registers.

Tim Northover tnorthover at apple.com
Thu May 30 05:30:50 PDT 2013


Author: tnorthover
Date: Thu May 30 07:30:50 2013
New Revision: 182925

URL: http://llvm.org/viewvc/llvm-project?rev=182925&view=rev
Log:
Fix rematerialization into physical registers.

r182872 introduced a bug in how the register-coalescer's rematerialization
handled defining a physical register. It relied on the output of the
coalescer's setRegisters method to determine whether the replacement
instruction needed an implicit-def. However, this value isn't necessarily the
same as the CopyMI's actual destination register which is what the rest of the
basic-block expects us to be defining.

The commit changes the rematerializer to use the actual register attached to
CopyMI in its decision.

This will be tested soon by an X86 patch which moves everything to using
MOV32r0 instead of other sizes.

Modified:
    llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp

Modified: llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp?rev=182925&r1=182924&r2=182925&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp (original)
+++ llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp Thu May 30 07:30:50 2013
@@ -762,6 +762,7 @@ bool RegisterCoalescer::reMaterializeTri
     return false;
   // Only support subregister destinations when the def is read-undef.
   MachineOperand &DstOperand = CopyMI->getOperand(0);
+  unsigned CopyDstReg = DstOperand.getReg();
   if (DstOperand.getSubReg() && !DstOperand.isUndef())
     return false;
 
@@ -837,12 +838,12 @@ bool RegisterCoalescer::reMaterializeTri
       NewMI->getOperand(0).setSubReg(
           TRI->composeSubRegIndices(SrcIdx, DefMI->getOperand(0).getSubReg()));
     }
-  } else if (NewMI->getOperand(0).getReg() != DstReg) {
+  } else if (NewMI->getOperand(0).getReg() != CopyDstReg) {
     // The New instruction may be defining a sub-register of what's actually
     // been asked for. If so it must implicitly define the whole thing.
     assert(TargetRegisterInfo::isPhysicalRegister(DstReg) &&
            "Only expect virtual or physical registers in remat");
-    NewMI->addOperand(MachineOperand::CreateReg(DstReg,
+    NewMI->addOperand(MachineOperand::CreateReg(CopyDstReg,
                                                 true  /*IsDef*/,
                                                 true  /*IsImp*/,
                                                 false /*IsKill*/));





More information about the llvm-commits mailing list