From eb83f4e6cd00c50989f14ba41857f6b9e42b9e5e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 17 Jun 2006 01:02:31 +0000 Subject: [PATCH] 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 --- lib/Transforms/Scalar/IndVarSimplify.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index 72ddb07d1eb..a46916077ae 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 ExtraLoopUsers; + std::vector ExtraLoopUsers; for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); - UI != E; ++UI) - if (!L->contains(cast(*UI)->getParent())) - ExtraLoopUsers.push_back(*UI); + UI != E; ++UI) { + Instruction *User = cast(*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(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 -- 2.34.1