[llvm-commits] [llvm] r54432 - /llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp
Owen Anderson
resistor at mac.com
Wed Aug 6 16:16:52 PDT 2008
Author: resistor
Date: Wed Aug 6 18:16:52 2008
New Revision: 54432
URL: http://llvm.org/viewvc/llvm-project?rev=54432&view=rev
Log:
SDISel's constant branch folding can fold away self-loops, which doesn't result in any dead blocks, but
rather an incorrect phi input. Add code to UnreachableMachineBlockElim to get rid of these entries.
Modified:
llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp
Modified: llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp?rev=54432&r1=54431&r2=54432&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp (original)
+++ llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp Wed Aug 6 18:16:52 2008
@@ -111,9 +111,11 @@
// Loop over all dead blocks, remembering them and deleting all instructions
// in them.
std::vector<MachineBasicBlock*> DeadBlocks;
- for (MachineFunction::iterator I = F.begin(), E = F.end(); I != E; ++I)
- if (!Reachable.count(I)) {
- MachineBasicBlock *BB = I;
+ for (MachineFunction::iterator I = F.begin(), E = F.end(); I != E; ++I) {
+ MachineBasicBlock *BB = I;
+
+ // Test for deadness.
+ if (!Reachable.count(BB)) {
DeadBlocks.push_back(BB);
while (BB->succ_begin() != BB->succ_end()) {
@@ -129,28 +131,51 @@
start->RemoveOperand(i-1);
}
- if (start->getNumOperands() == 3) {
- MachineInstr* phi = start;
- unsigned Input = phi->getOperand(1).getReg();
- unsigned Output = phi->getOperand(0).getReg();
-
- start++;
- phi->eraseFromParent();
-
- if (Input != Output)
- F.getRegInfo().replaceRegWith(Output, Input);
- } else
- start++;
+ start++;
}
BB->removeSuccessor(BB->succ_begin());
}
}
+ }
// Actually remove the blocks now.
for (unsigned i = 0, e = DeadBlocks.size(); i != e; ++i)
DeadBlocks[i]->eraseFromParent();
+ // Cleanup PHI nodes.
+ for (MachineFunction::iterator I = F.begin(), E = F.end(); I != E; ++I) {
+ MachineBasicBlock *BB = I;
+ // Prune unneeded PHI entries.
+ SmallPtrSet<MachineBasicBlock*, 8> preds(BB->pred_begin(),
+ BB->pred_end());
+ MachineBasicBlock::iterator phi = BB->begin();
+ while (phi != BB->end() &&
+ phi->getOpcode() == TargetInstrInfo::PHI) {
+ if (phi->getNumOperands() == 3) {
+ unsigned Input = phi->getOperand(1).getReg();
+ unsigned Output = phi->getOperand(0).getReg();
+
+ MachineInstr* temp = phi;
+ ++phi;
+ temp->eraseFromParent();
+
+ if (Input != Output)
+ F.getRegInfo().replaceRegWith(Output, Input);
+
+ continue;
+ }
+
+ for (unsigned i = phi->getNumOperands() - 1; i >= 2; i-=2)
+ if (!preds.count(phi->getOperand(i).getMBB())) {
+ phi->RemoveOperand(i);
+ phi->RemoveOperand(i-1);
+ }
+
+ ++phi;
+ }
+ }
+
F.RenumberBlocks();
return DeadBlocks.size();
More information about the llvm-commits
mailing list