Add an extra safety check in front of the optimization in r141442.
authorAndrew Trick <atrick@apple.com>
Sat, 8 Oct 2011 02:16:39 +0000 (02:16 +0000)
committerAndrew Trick <atrick@apple.com>
Sat, 8 Oct 2011 02:16:39 +0000 (02:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141470 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ScalarEvolutionExpander.cpp

index 3229c3c91564284ac0c652dfe17caec1a6e6a1b9..d0825b7eb5240976969e68d450384dd709a80442 100644 (file)
@@ -908,6 +908,15 @@ bool SCEVExpander::isExpandedAddRecExprPHI(PHINode *PN, Instruction *IncV,
       if (IncV->getType() != Type::getInt1PtrTy(SE.getContext(), AS)
           && IncV->getType() != Type::getInt8PtrTy(SE.getContext(), AS))
         return false;
+      // Ensure the operands dominate the insertion point. I don't know of a
+      // case when this would not be true, so this is somewhat untested.
+      if (L == IVIncInsertLoop) {
+        for (User::op_iterator OI = IncV->op_begin()+1,
+               OE = IncV->op_end(); OI != OE; ++OI)
+          if (Instruction *OInst = dyn_cast<Instruction>(OI))
+            if (!SE.DT->dominates(OInst, IVIncInsertPos))
+              return false;
+      }
       break;
     }
     IncV = dyn_cast<Instruction>(IncV->getOperand(0));