[PATCH] D117015: [InstSimplify] Fold inbounds GEP to poison if base is undef.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 11 05:45:28 PST 2022
fhahn created this revision.
fhahn added reviewers: nikic, spatel, lebedev.ri, aqjune.
Herald added a subscriber: hiraditya.
fhahn requested review of this revision.
Herald added a project: LLVM.
D92270 <https://reviews.llvm.org/D92270> updated constant expression folding to fold inbounds GEP to
poison if the base is undef. Apply the same logic to SimplifyGEPInst.
The justification is that we can choose an out-of-bounds pointer as base
pointer.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D117015
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 i64* @undef_inbounds_var_idx(i64 %idx) {
; CHECK-LABEL: @undef_inbounds_var_idx(
-; CHECK-NEXT: ret i64* undef
+; CHECK-NEXT: ret i64* poison
;
%el = getelementptr inbounds i64, i64* undef, i64 %idx
ret i64* %el
@@ -176,7 +176,7 @@
define <8 x i64*> @undef_vec1() {
; CHECK-LABEL: @undef_vec1(
-; CHECK-NEXT: ret <8 x i64*> undef
+; CHECK-NEXT: ret <8 x i64*> poison
;
%el = getelementptr inbounds i64, i64* undef, <8 x i64> undef
ret <8 x i64*> %el
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4457,7 +4457,8 @@
return PoisonValue::get(GEPTy);
if (Q.isUndefValue(Ops[0]))
- return UndefValue::get(GEPTy);
+ // If inbounds, we can choose an out-of-bounds pointer as a base pointer.
+ return InBounds ? PoisonValue::get(GEPTy) : UndefValue::get(GEPTy);
bool IsScalableVec =
isa<ScalableVectorType>(SrcTy) || any_of(Ops, [](const Value *V) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117015.398923.patch
Type: text/x-patch
Size: 1306 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220111/64bbedac/attachment.bin>
More information about the llvm-commits
mailing list