handle special cases when findGCD returns 1
authorSebastian Pop <spop@codeaurora.org>
Tue, 8 Apr 2014 21:21:10 +0000 (21:21 +0000)
committerSebastian Pop <spop@codeaurora.org>
Tue, 8 Apr 2014 21:21:10 +0000 (21:21 +0000)
used to fail with 'Step should divide Start with no remainder.'

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205801 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ScalarEvolution.cpp

index d6165111dbabf29324b7e5ec949bfec1b71bc33c..6ccf8aac3b893c4ba3b8ec344cf980ee7eb1bad0 100644 (file)
@@ -7001,12 +7001,17 @@ public:
 
     const SCEV *Rem = Zero;
     const SCEV *Res = findGCD(SE, Expr->getOperand(0), GCD, &Rem);
+    if (Res == One || Res->isAllOnesValue()) {
+      Remainder = Expr;
+      return GCD;
+    }
+
     if (Rem != Zero)
       Remainder = SE.getAddExpr(Remainder, Rem);
 
     Rem = Zero;
     Res = findGCD(SE, Expr->getOperand(1), Res, &Rem);
-    if (Rem != Zero) {
+    if (Rem != Zero || Res == One || Res->isAllOnesValue()) {
       Remainder = Expr;
       return GCD;
     }