diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -4896,9 +4896,9 @@ any_of(Indices, [](const auto *V) { return isa(V); })) return PoisonValue::get(GEPTy); + // getelementptr undef, idx -> undef if (Q.isUndefValue(Ptr)) - // If inbounds, we can choose an out-of-bounds pointer as a base pointer. - return InBounds ? PoisonValue::get(GEPTy) : UndefValue::get(GEPTy); + return UndefValue::get(GEPTy); bool IsScalableVec = isa(SrcTy) || any_of(Indices, [](const Value *V) { diff --git a/llvm/test/Transforms/InstSimplify/gep.ll b/llvm/test/Transforms/InstSimplify/gep.ll --- a/llvm/test/Transforms/InstSimplify/gep.ll +++ b/llvm/test/Transforms/InstSimplify/gep.ll @@ -160,7 +160,7 @@ define ptr @undef_inbounds_var_idx(i64 %idx) { ; CHECK-LABEL: @undef_inbounds_var_idx( -; CHECK-NEXT: ret ptr poison +; CHECK-NEXT: ret ptr undef ; %el = getelementptr inbounds i64, ptr undef, i64 %idx ret ptr %el @@ -176,7 +176,7 @@ define <8 x ptr> @undef_vec1() { ; CHECK-LABEL: @undef_vec1( -; CHECK-NEXT: ret <8 x ptr> poison +; CHECK-NEXT: ret <8 x ptr> undef ; %el = getelementptr inbounds i64, ptr undef, <8 x i64> undef ret <8 x ptr> %el