diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index d6ed6437656533..76223f353288c7 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -822,7 +822,8 @@ Constant *SymbolicallyEvaluateBinop(unsigned Opc, Constant *Op0, Constant *Op1, /// If array indices are not pointer-sized integers, explicitly cast them so /// that they aren't implicitly casted by the getelementptr. Constant *CastGEPIndices(Type *SrcElemTy, ArrayRef Ops, - Type *ResultTy, std::optional InRangeIndex, + Type *ResultTy, bool InBounds, + std::optional InRangeIndex, const DataLayout &DL, const TargetLibraryInfo *TLI) { Type *IntIdxTy = DL.getIndexType(ResultTy); Type *IntIdxScalarTy = IntIdxTy->getScalarType(); @@ -851,7 +852,7 @@ Constant *CastGEPIndices(Type *SrcElemTy, ArrayRef Ops, return nullptr; Constant *C = ConstantExpr::getGetElementPtr( - SrcElemTy, Ops[0], NewIdxs, /*InBounds=*/false, InRangeIndex); + SrcElemTy, Ops[0], NewIdxs, InBounds, InRangeIndex); return ConstantFoldConstant(C, DL, TLI); } @@ -886,7 +887,8 @@ Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP, return nullptr; if (Constant *C = CastGEPIndices(SrcElemTy, Ops, ResTy, - GEP->getInRangeIndex(), DL, TLI)) + GEP->isInBounds(), GEP->getInRangeIndex(), + DL, TLI)) return C; Constant *Ptr = Ops[0]; diff --git a/llvm/test/Other/constant-fold-gep.ll b/llvm/test/Other/constant-fold-gep.ll index 4bc9d29553df3e..0c1ca129bdb382 100644 --- a/llvm/test/Other/constant-fold-gep.ll +++ b/llvm/test/Other/constant-fold-gep.ll @@ -457,7 +457,7 @@ define ptr @different_addrspace() nounwind noinline { %p = getelementptr inbounds i8, ptr addrspacecast (ptr addrspace(12) @p12 to ptr), i32 2 ret ptr %p -; OPT: ret ptr getelementptr (i8, ptr addrspacecast (ptr addrspace(12) @p12 to ptr), i64 2) +; OPT: ret ptr getelementptr inbounds (i8, ptr addrspacecast (ptr addrspace(12) @p12 to ptr), i64 2) } define ptr @same_addrspace() nounwind noinline { diff --git a/llvm/test/Transforms/GVN/constexpr-vector-constainsundef-crash-inseltpoison.ll b/llvm/test/Transforms/GVN/constexpr-vector-constainsundef-crash-inseltpoison.ll index fb2133182503ac..a40811aa1dde15 100644 --- a/llvm/test/Transforms/GVN/constexpr-vector-constainsundef-crash-inseltpoison.ll +++ b/llvm/test/Transforms/GVN/constexpr-vector-constainsundef-crash-inseltpoison.ll @@ -9,7 +9,7 @@ define <4 x ptr> @test(ptr %ptr) { ; CHECK-LABEL: @test( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[L3:%.*]] = load i64, ptr [[PTR:%.*]], align 4 -; CHECK-NEXT: [[I6:%.*]] = insertelement <4 x ptr> getelementptr (i64, ptr null, <4 x i64> ), ptr undef, i64 [[L3]] +; CHECK-NEXT: [[I6:%.*]] = insertelement <4 x ptr> getelementptr inbounds (i64, ptr null, <4 x i64> ), ptr undef, i64 [[L3]] ; CHECK-NEXT: ret <4 x ptr> [[I6]] ; entry: diff --git a/llvm/test/Transforms/GVN/constexpr-vector-constainsundef-crash.ll b/llvm/test/Transforms/GVN/constexpr-vector-constainsundef-crash.ll index 276008f6348a32..ddb223fffab5ec 100644 --- a/llvm/test/Transforms/GVN/constexpr-vector-constainsundef-crash.ll +++ b/llvm/test/Transforms/GVN/constexpr-vector-constainsundef-crash.ll @@ -8,7 +8,9 @@ define <4 x ptr> @test(ptr %ptr) { ; CHECK-LABEL: @test( ; CHECK-NEXT: entry: -; CHECK-NEXT: ret <4 x ptr> getelementptr (i64, ptr null, <4 x i64> ) +; CHECK-NEXT: [[L3:%.*]] = load i64, ptr [[PTR:%.*]], align 4 +; CHECK-NEXT: [[I6:%.*]] = insertelement <4 x ptr> getelementptr inbounds (i64, ptr null, <4 x i64> ), ptr undef, i64 [[L3]] +; CHECK-NEXT: ret <4 x ptr> [[I6]] ; entry: %B9 = sdiv i16 -32768, 256 diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/cast-vector.ll b/llvm/test/Transforms/InstSimplify/ConstProp/cast-vector.ll index 83ef0c14592cb7..3e4504a1663661 100644 --- a/llvm/test/Transforms/InstSimplify/ConstProp/cast-vector.ll +++ b/llvm/test/Transforms/InstSimplify/ConstProp/cast-vector.ll @@ -8,7 +8,7 @@ define <2 x i16> @test1() { ; CHECK-LABEL: @test1( ; CHECK-NEXT: entry: -; CHECK-NEXT: ret <2 x i16> ptrtoint (<2 x ptr> getelementptr ([10 x i32], ptr null, <2 x i64> zeroinitializer, <2 x i64> ) to <2 x i16>) +; CHECK-NEXT: ret <2 x i16> ptrtoint (<2 x ptr> getelementptr inbounds ([10 x i32], ptr null, <2 x i64> zeroinitializer, <2 x i64> ) to <2 x i16>) ; entry: %gep = getelementptr inbounds [10 x i32], ptr null, i16 0, <2 x i16>