]> granicus.if.org Git - llvm/commitdiff
[Constants] don't die processing non-ConstantInt GEP indices in isGEPWithNoNotionalOv...
authorSanjay Patel <spatel@rotateright.com>
Sun, 11 Dec 2016 20:07:02 +0000 (20:07 +0000)
committerSanjay Patel <spatel@rotateright.com>
Sun, 11 Dec 2016 20:07:02 +0000 (20:07 +0000)
This should fix:
https://llvm.org/bugs/show_bug.cgi?id=31262

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

lib/IR/Constants.cpp
test/Transforms/InstSimplify/compare.ll

index 6a6820234a01fbccff9b49526273f14b12c6e6b7..a3db15259311534bffed29ce4caf4983e79db0f3 100644 (file)
@@ -1071,13 +1071,15 @@ bool ConstantExpr::isGEPWithNoNotionalOverIndexing() const {
   gep_type_iterator GEPI = gep_type_begin(this), E = gep_type_end(this);
   User::const_op_iterator OI = std::next(this->op_begin());
 
-  // The remaining indices must be compile-time known integers within the
-  // bounds of the corresponding notional static array types.
+  // The remaining indices may be compile-time known integers within the bounds
+  // of the corresponding notional static array types.
   for (; GEPI != E; ++GEPI, ++OI) {
-    ConstantInt *CI = dyn_cast<ConstantInt>(*OI);
-    if (GEPI.isBoundedSequential() &&
-        (CI->getValue().getActiveBits() > 64 ||
-         CI->getZExtValue() >= GEPI.getSequentialNumElements()))
+    if (isa<UndefValue>(*OI))
+      continue;
+    auto *CI = dyn_cast<ConstantInt>(*OI);
+    if (!CI || (GEPI.isBoundedSequential() &&
+                (CI->getValue().getActiveBits() > 64 ||
+                 CI->getZExtValue() >= GEPI.getSequentialNumElements())))
       return false;
   }
 
index e5aea26b5aaab81a512fb619e1ad81c41e812b05..cd2fa880294ad71256b10b2c981edcc3ef2aaf77 100644 (file)
@@ -65,6 +65,17 @@ define i1 @gep4() {
 ; CHECK-NEXT: ret i1 false
 }
 
+@a = common global [1 x i32] zeroinitializer, align 4
+
+define i1 @PR31262() {
+; CHECK-LABEL: @PR31262(
+; CHECK-NEXT:    ret i1 icmp uge (i32* getelementptr ([1 x i32], [1 x i32]* @a, i64 0, i64 undef), i32* getelementptr inbounds ([1 x i32], [1 x i32]* @a, i32 0, i32 0))
+;
+  %idx = getelementptr inbounds [1 x i32], [1 x i32]* @a, i64 0, i64 undef
+  %cmp = icmp uge i32* %idx, getelementptr inbounds ([1 x i32], [1 x i32]* @a, i32 0, i32 0)
+  ret i1 %cmp
+}
+
 define i1 @gep5() {
 ; CHECK-LABEL: @gep5(
   %x = alloca %gept, align 8