Skip to content

Commit

Permalink
[InstSimplify] Fold gep inbounds undef to undef instead of poison
Browse files Browse the repository at this point in the history
With the semantics change from D154051, it is no longer valid to
fold gep inbounds undef to poison (unless we know the index is
non-zero). Fold it to undef instead.

Differential Revision: https://reviews.llvm.org/D154215
  • Loading branch information
nikic committed Jul 6, 2023
1 parent 5861b4c commit 6c7fd72
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4896,9 +4896,9 @@ static Value *simplifyGEPInst(Type *SrcTy, Value *Ptr,
any_of(Indices, [](const auto *V) { return isa<PoisonValue>(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<ScalableVectorType>(SrcTy) || any_of(Indices, [](const Value *V) {
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Transforms/InstSimplify/gep.ll
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ define ptr @test7(ptr %b, ptr %e) {

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
Expand All @@ -176,7 +176,7 @@ define ptr @undef_no_inbounds_var_idx(i64 %idx) {

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
Expand Down

0 comments on commit 6c7fd72

Please sign in to comment.