[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 10:55:47 PST 2018
fhahn updated this revision to Diff 177883.
fhahn added a comment.
rebased
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D55536/new/
https://reviews.llvm.org/D55536
Files:
lib/IR/ConstantFold.cpp
test/Transforms/SCCP/apint-bigint2.ll
Index: test/Transforms/SCCP/apint-bigint2.ll
===================================================================
--- test/Transforms/SCCP/apint-bigint2.ll
+++ 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
+}
Index: lib/IR/ConstantFold.cpp
===================================================================
--- lib/IR/ConstantFold.cpp
+++ 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55536.177883.patch
Type: text/x-patch
Size: 1425 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181212/699e0507/attachment-0001.bin>
More information about the llvm-commits
mailing list