aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineLICM.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-10-28 15:23:36 +0000
committerDan Gohman <gohman@apple.com>2009-10-28 15:23:36 +0000
commit57780dfdfc3ec2d05aba1fa95491b51bae15cc8b (patch)
treefa431e2f4d9ad0ea7d51dbbbcc8efdb9dac9a07b /llvm/lib/CodeGen/MachineLICM.cpp
parent5c5214626cdc363508dfd133dc286e57ce1e7942 (diff)
downloadllvm-57780dfdfc3ec2d05aba1fa95491b51bae15cc8b.zip
llvm-57780dfdfc3ec2d05aba1fa95491b51bae15cc8b.tar.gz
llvm-57780dfdfc3ec2d05aba1fa95491b51bae15cc8b.tar.bz2
Simplify this code: if the unfolded load can't be hoisted, just delete
the new instructions and leave the old one in place. llvm-svn: 85393
Diffstat (limited to 'llvm/lib/CodeGen/MachineLICM.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineLICM.cpp19
1 files changed, 3 insertions, 16 deletions
diff --git a/llvm/lib/CodeGen/MachineLICM.cpp b/llvm/lib/CodeGen/MachineLICM.cpp
index d63cd0e..cf958f5a 100644
--- a/llvm/lib/CodeGen/MachineLICM.cpp
+++ b/llvm/lib/CodeGen/MachineLICM.cpp
@@ -401,7 +401,7 @@ void MachineLICM::Hoist(MachineInstr *MI) {
const TargetRegisterClass *RC = TID.OpInfo[0].getRegClass(TRI);
// Ok, we're unfolding. Create a temporary register and do the unfold.
unsigned Reg = RegInfo->createVirtualRegister(RC);
- SmallVector<MachineInstr *, 1> NewMIs;
+ SmallVector<MachineInstr *, 2> NewMIs;
bool Success =
TII->unfoldMemoryOperand(MF, MI, Reg,
/*UnfoldLoad=*/true, /*UnfoldStore=*/false,
@@ -415,28 +415,15 @@ void MachineLICM::Hoist(MachineInstr *MI) {
MachineBasicBlock *MBB = MI->getParent();
MBB->insert(MI, NewMIs[0]);
MBB->insert(MI, NewMIs[1]);
- MI->eraseFromParent();
// If unfolding produced a load that wasn't loop-invariant or profitable to
- // hoist, re-fold it to undo the damage.
+ // hoist, discard the new instructions and bail.
if (!IsLoopInvariantInst(*NewMIs[0]) || !IsProfitableToHoist(*NewMIs[0])) {
- SmallVector<unsigned, 1> Ops;
- for (unsigned i = 0, e = NewMIs[1]->getNumOperands(); i != e; ++i) {
- MachineOperand &MO = NewMIs[1]->getOperand(i);
- if (MO.isReg() && MO.getReg() == Reg) {
- assert(MO.isUse() &&
- "Register defined by unfolded load is redefined "
- "instead of just used!");
- Ops.push_back(i);
- }
- }
- MI = TII->foldMemoryOperand(MF, NewMIs[1], Ops, NewMIs[0]);
- assert(MI && "Re-fold failed!");
- MBB->insert(NewMIs[1], MI);
NewMIs[0]->eraseFromParent();
NewMIs[1]->eraseFromParent();
return;
}
// Otherwise we successfully unfolded a load that we can hoist.
+ MI->eraseFromParent();
MI = NewMIs[0];
}