[llvm] r259815 - Fix a regression for r259736.

Wei Mi via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 4 11:17:34 PST 2016


Author: wmi
Date: Thu Feb  4 13:17:33 2016
New Revision: 259815

URL: http://llvm.org/viewvc/llvm-project?rev=259815&view=rev
Log:
Fix a regression for r259736.

When SCEV expansion tries to reuse an existing value, it is needed to ensure
that using the Value at the InsertPt will not break LCSSA. The fix adds a
check that InsertPt is either inside the candidate Value's parent loop, or
the candidate Value's parent loop is nullptr.


Modified:
    llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp

Modified: llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp?rev=259815&r1=259814&r2=259815&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp Thu Feb  4 13:17:33 2016
@@ -1652,10 +1652,17 @@ Value *SCEVExpander::expand(const SCEV *
     // If S is scConstant, it may be worse to reuse an existing Value.
     if (S->getSCEVType() != scConstant && Set) {
       // Choose a Value from the set which dominates the insertPt.
+      // insertPt should be inside the Value's parent loop so as not to break
+      // the LCSSA form.
       for (auto const &Ent : *Set) {
-        if (Ent && isa<Instruction>(Ent) && S->getType() == Ent->getType() &&
-            cast<Instruction>(Ent)->getFunction() == InsertPt->getFunction() &&
-            SE.DT.dominates(cast<Instruction>(Ent), InsertPt)) {
+        Instruction *EntInst = nullptr;
+        if (Ent && isa<Instruction>(Ent) &&
+            (EntInst = cast<Instruction>(Ent)) &&
+            S->getType() == Ent->getType() &&
+            EntInst->getFunction() == InsertPt->getFunction() &&
+            SE.DT.dominates(EntInst, InsertPt) &&
+            (SE.LI.getLoopFor(EntInst->getParent()) == nullptr ||
+             SE.LI.getLoopFor(EntInst->getParent())->contains(InsertPt))) {
           V = Ent;
           break;
         }




More information about the llvm-commits mailing list