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 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 +}