[llvm-commits] [llvm] r103680 - /llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp
Evan Cheng
evan.cheng at apple.com
Wed May 12 17:00:35 PDT 2010
Author: evancheng
Date: Wed May 12 19:00:35 2010
New Revision: 103680
URL: http://llvm.org/viewvc/llvm-project?rev=103680&view=rev
Log:
If REG_SEQUENCE source is livein, copy it first. Also, update livevariables information when a copy is introduced.
Modified:
llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp
Modified: llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp?rev=103680&r1=103679&r2=103680&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp (original)
+++ llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp Wed May 12 19:00:35 2010
@@ -1175,17 +1175,36 @@
llvm_unreachable(0);
}
- if (!Seen.insert(SrcReg)) {
- // REG_SEQUENCE cannot have duplicated operands. Add a copy.
+ MachineInstr *DefMI = MRI->getVRegDef(SrcReg);
+ if (!Seen.insert(SrcReg) || MI->getParent() != DefMI->getParent()) {
+ // REG_SEQUENCE cannot have duplicated operands, add a copy.
+ // Also add an copy if the source if live-in the block. We don't want
+ // to end up with a partial-redef of a livein, e.g.
+ // BB0:
+ // reg1051:10<def> =
+ // ...
+ // BB1:
+ // ... = reg1051:10
+ // BB2:
+ // reg1051:9<def> =
+ // LiveIntervalAnalysis won't like it.
const TargetRegisterClass *RC = MRI->getRegClass(SrcReg);
unsigned NewReg = MRI->createVirtualRegister(RC);
+ MachineBasicBlock::iterator InsertLoc = MI;
bool Emitted =
- TII->copyRegToReg(*MI->getParent(), MI, NewReg, SrcReg, RC, RC,
+ TII->copyRegToReg(*MI->getParent(), InsertLoc, 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();
+ if (MI->getOperand(i).isKill()) {
+ MachineBasicBlock::iterator CopyMI = prior(InsertLoc);
+ MachineOperand *KillMO = CopyMI->findRegisterUseOperand(SrcReg);
+ KillMO->setIsKill();
+ if (LV)
+ // Update live variables
+ LV->replaceKillInstruction(SrcReg, MI, &*CopyMI);
+ }
}
}
More information about the llvm-commits
mailing list