[llvm] 6c7fd72 - [InstSimplify] Fold gep inbounds undef to undef instead of poison
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 6 05:59:29 PDT 2023
Author: Nikita Popov
Date: 2023-07-06T14:59:22+02:00
New Revision: 6c7fd723c460dee6546b3b876a0dfee8c996d7d8
URL: https://github.com/llvm/llvm-project/commit/6c7fd723c460dee6546b3b876a0dfee8c996d7d8
DIFF: https://github.com/llvm/llvm-project/commit/6c7fd723c460dee6546b3b876a0dfee8c996d7d8.diff
LOG: [InstSimplify] Fold gep inbounds undef to undef instead of poison
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
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/gep.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index a32f6880e642b6..8599847dddb5e7 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -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) {
diff --git a/llvm/test/Transforms/InstSimplify/gep.ll b/llvm/test/Transforms/InstSimplify/gep.ll
index 529fc5ed960a07..5e70c2ca37c3a2 100644
--- a/llvm/test/Transforms/InstSimplify/gep.ll
+++ b/llvm/test/Transforms/InstSimplify/gep.ll
@@ -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
@@ -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
More information about the llvm-commits
mailing list