Fix crasher introduced in r200203 and caught by a libc++ buildbot. Don't assume that...
authorNick Lewycky <nicholas@mxc.ca>
Mon, 27 Jan 2014 10:47:44 +0000 (10:47 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Mon, 27 Jan 2014 10:47:44 +0000 (10:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200210 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ScalarEvolution.cpp
test/Analysis/ScalarEvolution/fold.ll

index e8ee46dff8ca9304370b486328f36a4722b7a1ad..1a15144863dc302c190fdac64be938769aa38c24 100644 (file)
@@ -2292,7 +2292,9 @@ const SCEV *ScalarEvolution::getUDivExactExpr(const SCEV *LHS,
         Operands.append(Mul->op_begin() + 1, Mul->op_end());
         LHS = getMulExpr(Operands);
         RHS = RHSCst;
-        Mul = cast<SCEVMulExpr>(LHS);
+        Mul = dyn_cast<SCEVMulExpr>(LHS);
+        if (!Mul)
+          return getUDivExactExpr(LHS, RHS);
       }
     }
   }
index 84b657050c535ef8bcb9b9713a617cb6777555f0..ab5742557b33aef4e11964dc1b711934cc0bcc72 100644 (file)
@@ -77,3 +77,12 @@ define void @test5(i32 %i) {
 ; CHECK: -->  (-2147483648 * (%i /u -2147483648))
   ret void
 }
+
+define void @test6(i8 %x) {
+; CHECK-LABEL: @test6
+  %A = zext i8 %x to i16
+  %B = shl nuw i16 %A, 8
+  %C = and i16 %B, -2048
+; CHECK: -->  (2048 * ((zext i8 %x to i16) /u 8))
+  ret void
+}