[FIX] Compare SCEVs not values during SCEV expansion
authorJohannes Doerfert <doerfert@cs.uni-saarland.de>
Sun, 21 Feb 2016 16:36:00 +0000 (16:36 +0000)
committerJohannes Doerfert <doerfert@cs.uni-saarland.de>
Sun, 21 Feb 2016 16:36:00 +0000 (16:36 +0000)
  This fixes a compile time bug in SPEC2006 403.gcc, namely an endless
  recursion in the ScopExpander::visitUnknown function.

llvm-svn: 261474

polly/lib/Support/ScopHelper.cpp

index 63f91b8..f845be8 100644 (file)
@@ -249,10 +249,15 @@ private:
   const SCEV *visitUnknown(const SCEVUnknown *E) {
 
     // If a value mapping was given try if the underlying value is remapped.
-    if (VMap)
-      if (Value *NewVal = VMap->lookup(E->getValue()))
-        if (NewVal != E->getValue())
-          return visit(SE.getSCEV(NewVal));
+    Value *NewVal = VMap ? VMap->lookup(E->getValue()) : nullptr;
+    if (NewVal) {
+      auto *NewE = SE.getSCEV(NewVal);
+
+      // While the mapped value might be different the SCEV representation might
+      // not be. To this end we will check before we go into recursion here.
+      if (E != NewE)
+        return visit(NewE);
+    }
 
     Instruction *Inst = dyn_cast<Instruction>(E->getValue());
     if (!Inst || (Inst->getOpcode() != Instruction::SRem &&