OSDN Git Service

[SCCP] Don't assume all Constants are ConstantInt
authorDavid Majnemer <david.majnemer@gmail.com>
Thu, 23 Jun 2016 00:14:29 +0000 (00:14 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Thu, 23 Jun 2016 00:14:29 +0000 (00:14 +0000)
This fixes PR28269.

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

lib/Transforms/Scalar/SCCP.cpp
test/Transforms/SCCP/undef-resolve.ll

index 83f087f..91e625b 100644 (file)
@@ -1419,10 +1419,10 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
 
         // Shifting by the bitwidth or more is undefined.
         if (Op1LV.isConstant()) {
-          auto *ShiftAmt = Op1LV.getConstantInt();
-          if (ShiftAmt->getLimitedValue() >=
-              ShiftAmt->getType()->getScalarSizeInBits())
-            break;
+          if (auto *ShiftAmt = Op1LV.getConstantInt())
+            if (ShiftAmt->getLimitedValue() >=
+                ShiftAmt->getType()->getScalarSizeInBits())
+              break;
         }
 
         // undef >>a X -> all ones
@@ -1436,10 +1436,10 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
 
         // Shifting by the bitwidth or more is undefined.
         if (Op1LV.isConstant()) {
-          auto *ShiftAmt = Op1LV.getConstantInt();
-          if (ShiftAmt->getLimitedValue() >=
-              ShiftAmt->getType()->getScalarSizeInBits())
-            break;
+          if (auto *ShiftAmt = Op1LV.getConstantInt())
+            if (ShiftAmt->getLimitedValue() >=
+                ShiftAmt->getType()->getScalarSizeInBits())
+              break;
         }
 
         // undef << X -> 0
index 2b40183..fcfe3f5 100644 (file)
@@ -170,3 +170,13 @@ entry:
 ; CHECK-LABEL: @test10(
 ; CHECK: ret i64 undef
 }
+
+@GV = external global i32
+
+define i32 @test11(i1 %tobool) {
+entry:
+  %shr4 = ashr i32 undef, zext (i1 icmp eq (i32* bitcast (i32 (i1)* @test11 to i32*), i32* @GV) to i32)
+  ret i32 %shr4
+; CHECK-LABEL: @test11(
+; CHECK: ret i32 -1
+}