aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/IndVarSimplify.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-06-17 01:02:31 +0000
committerChris Lattner <sabre@nondot.org>2006-06-17 01:02:31 +0000
commiteb83f4e6cd00c50989f14ba41857f6b9e42b9e5e (patch)
tree457d39868b7857e295bd07e1fcf7a8ebe0062156 /lib/Transforms/Scalar/IndVarSimplify.cpp
parent98c3e1cc928e505caa376e10dacb1cbcad0efb8a (diff)
Fix IndVarsSimplify/2006-06-16-Indvar-LCSSA-Crash.ll, a case where a
"LCSSA" phi node causes indvars to break dominance properties. This fixes causes indvars to avoid inserting aggressive code in this case, instead indvars should be fixed to be more aggressive in the face of lcssa phi's. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28850 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/IndVarSimplify.cpp')
-rw-r--r--lib/Transforms/Scalar/IndVarSimplify.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp
index 72ddb07d1e..a46916077a 100644
--- a/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -321,11 +321,26 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L) {
HasConstantItCount) {
// Find out if this predictably varying value is actually used
// outside of the loop. "extra" as opposed to "intra".
- std::vector<User*> ExtraLoopUsers;
+ std::vector<Instruction*> ExtraLoopUsers;
for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
- UI != E; ++UI)
- if (!L->contains(cast<Instruction>(*UI)->getParent()))
- ExtraLoopUsers.push_back(*UI);
+ UI != E; ++UI) {
+ Instruction *User = cast<Instruction>(*UI);
+ if (!L->contains(User->getParent())) {
+ // If this is a PHI node in the exit block and we're inserting,
+ // into the exit block, it must have a single entry. In this
+ // case, we can't insert the code after the PHI and have the PHI
+ // still use it. Instead, don't insert the the PHI.
+ if (PHINode *PN = dyn_cast<PHINode>(User)) {
+ // FIXME: This is a case where LCSSA pessimizes code, this
+ // should be fixed better.
+ if (PN->getNumOperands() == 2 &&
+ PN->getParent() == BlockToInsertInto)
+ continue;
+ }
+ ExtraLoopUsers.push_back(User);
+ }
+ }
+
if (!ExtraLoopUsers.empty()) {
// Okay, this instruction has a user outside of the current loop
// and varies predictably in this loop. Evaluate the value it