Skip to content

Commit 69cd121

Browse files
committed
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. llvm-svn: 182925
1 parent 994d66a commit 69cd121

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

llvm/lib/CodeGen/RegisterCoalescer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ bool RegisterCoalescer::reMaterializeTrivialDef(CoalescerPair &CP,
762762
return false;
763763
// Only support subregister destinations when the def is read-undef.
764764
MachineOperand &DstOperand = CopyMI->getOperand(0);
765+
unsigned CopyDstReg = DstOperand.getReg();
765766
if (DstOperand.getSubReg() && !DstOperand.isUndef())
766767
return false;
767768

@@ -837,12 +838,12 @@ bool RegisterCoalescer::reMaterializeTrivialDef(CoalescerPair &CP,
837838
NewMI->getOperand(0).setSubReg(
838839
TRI->composeSubRegIndices(SrcIdx, DefMI->getOperand(0).getSubReg()));
839840
}
840-
} else if (NewMI->getOperand(0).getReg() != DstReg) {
841+
} else if (NewMI->getOperand(0).getReg() != CopyDstReg) {
841842
// The New instruction may be defining a sub-register of what's actually
842843
// been asked for. If so it must implicitly define the whole thing.
843844
assert(TargetRegisterInfo::isPhysicalRegister(DstReg) &&
844845
"Only expect virtual or physical registers in remat");
845-
NewMI->addOperand(MachineOperand::CreateReg(DstReg,
846+
NewMI->addOperand(MachineOperand::CreateReg(CopyDstReg,
846847
true /*IsDef*/,
847848
true /*IsImp*/,
848849
false /*IsKill*/));

0 commit comments

Comments
 (0)