[PATCH] D55536: [ConstantFold] Use getMinSignedBits for APInt in isIndexInRangeOfArrayType.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 12 11:00:24 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL348957: [ConstantFold] Use getMinSignedBits for APInt in isIndexInRangeOfArrayType. (authored by fhahn, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55536?vs=177883&id=177884#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55536/new/

https://reviews.llvm.org/D55536

Files:
  llvm/trunk/lib/IR/ConstantFold.cpp
  llvm/trunk/test/Transforms/SCCP/apint-bigint2.ll


Index: llvm/trunk/lib/IR/ConstantFold.cpp
===================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp
+++ llvm/trunk/lib/IR/ConstantFold.cpp
@@ -2053,7 +2053,7 @@
 static bool isIndexInRangeOfArrayType(uint64_t NumElements,
                                       const ConstantInt *CI) {
   // We cannot bounds check the index if it doesn't fit in an int64_t.
-  if (CI->getValue().getActiveBits() > 64)
+  if (CI->getValue().getMinSignedBits() > 64)
     return false;
 
   // A negative index or an index past the end of our sequential type is
Index: llvm/trunk/test/Transforms/SCCP/apint-bigint2.ll
===================================================================
--- llvm/trunk/test/Transforms/SCCP/apint-bigint2.ll
+++ llvm/trunk/test/Transforms/SCCP/apint-bigint2.ll
@@ -13,7 +13,7 @@
    %E = trunc i101 %DD to i32
    %F = getelementptr [6 x i101], [6 x i101]* @Y, i32 0, i32 %E
    %G = load i101, i101* %F
- 
+
    ret i101 %G
 }
 
@@ -28,3 +28,13 @@
   %L3 = load i101, i101* %G
   ret i101 %L3
 }
+
+; CHECK-LABEL: @index_too_large
+; CHECK-NEXT: store i101* getelementptr (i101, i101* getelementptr ([6 x i101], [6 x i101]* @Y, i32 0, i32 -1), i101 9224497936761618431), i101** undef
+; CHECK-NEXT: ret void
+define void @index_too_large() {
+  %ptr1 = getelementptr [6 x i101], [6 x i101]* @Y, i32 0, i32 -1
+  %ptr2 = getelementptr i101, i101* %ptr1, i101 9224497936761618431
+  store i101* %ptr2, i101** undef
+  ret void
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55536.177884.patch
Type: text/x-patch
Size: 1491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181212/0552caa2/attachment.bin>


More information about the llvm-commits mailing list