[PATCH] D154215: [InstSimplify] Fold gep inbounds undef to undef instead of poison
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 30 06:34:18 PDT 2023
nikic created this revision.
Herald added subscribers: nlopes, StephenFan, hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
With the semantics change from D154051 <https://reviews.llvm.org/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.
Depends on D154051 <https://reviews.llvm.org/D154051>.
https://reviews.llvm.org/D154215
Files:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/gep.ll
Index: llvm/test/Transforms/InstSimplify/gep.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/gep.ll
+++ 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
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4896,9 +4896,9 @@
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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154215.536211.patch
Type: text/x-patch
Size: 1412 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230630/13707605/attachment.bin>
More information about the llvm-commits
mailing list