summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-01-19 00:36:37 +0000
committerChris Lattner <sabre@nondot.org>2009-01-19 00:36:37 +0000
commit54f0c61d71ae49456db2289f5bdc9f09ccb0a604 (patch)
tree2a5a03bdd71eadf3806aee3d9754de5e86ba5f9f /llvm/lib/Transforms/Utils/SimplifyCFG.cpp
parentc215cfc3e1804565690f04bbb507e7aae3a38359 (diff)
downloadbcm5719-llvm-54f0c61d71ae49456db2289f5bdc9f09ccb0a604.tar.gz
bcm5719-llvm-54f0c61d71ae49456db2289f5bdc9f09ccb0a604.zip
Fix some problems in SpeculativelyExecuteBB. Basically,
because of dead code, a phi could use the speculated instruction that was not in "BB2". Make this check explicit and tighten up some other corners. This fixes PR3292. No testcase becauase this depends entirely on visitation order of blocks and requires a sequence of 8 passes to repro. llvm-svn: 62476
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 1a0b0b4b66d..2bd3209b00c 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -984,6 +984,12 @@ static bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *BB1) {
return false;
break; // These are all cheap and non-trapping instructions.
}
+
+ // If the instruction is obviously dead, don't try to predicate it.
+ if (I->use_empty()) {
+ I->eraseFromParent();
+ return true;
+ }
// Can we speculatively execute the instruction? And what is the value
// if the condition is false? Consider the phi uses, if the incoming value
@@ -992,20 +998,25 @@ static bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *BB1) {
BasicBlock *BIParent = BI->getParent();
SmallVector<PHINode*, 4> PHIUses;
Value *FalseV = NULL;
+
+ BasicBlock *BB2 = BB1->getTerminator()->getSuccessor(0);
for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
UI != E; ++UI) {
+ // Ignore any user that is not a PHI node in BB2. These can only occur in
+ // unreachable blocks, because they would not be dominated by the instr.
PHINode *PN = dyn_cast<PHINode>(UI);
- if (!PN)
- continue;
+ if (!PN || PN->getParent() != BB2)
+ return false;
PHIUses.push_back(PN);
+
Value *PHIV = PN->getIncomingValueForBlock(BIParent);
if (!FalseV)
FalseV = PHIV;
else if (FalseV != PHIV)
- return false; // Don't know the value when condition is false.
+ return false; // Inconsistent value when condition is false.
}
- if (!FalseV) // Can this happen?
- return false;
+
+ assert(FalseV && "Must have at least one user, and it must be a PHI");
// Do not hoist the instruction if any of its operands are defined but not
// used in this BB. The transformation will prevent the operand from
OpenPOWER on IntegriCloud