[llvm] c5aa983 - [InstSimplify] Fold all poison phi to poison instead of undef
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 25 05:28:21 PDT 2024
Author: Nikita Popov
Date: 2024-06-25T14:28:13+02:00
New Revision: c5aa983f91f0543b43926a32d2f70bb53f9945a2
URL: https://github.com/llvm/llvm-project/commit/c5aa983f91f0543b43926a32d2f70bb53f9945a2
DIFF: https://github.com/llvm/llvm-project/commit/c5aa983f91f0543b43926a32d2f70bb53f9945a2.diff
LOG: [InstSimplify] Fold all poison phi to poison instead of undef
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstCombine/shift.ll
llvm/test/Transforms/InstSimplify/phi.ll
llvm/test/Transforms/LoopDeletion/update-scev.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 00ce0e264906e..a452add93a7e7 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5248,11 +5248,16 @@ static Value *simplifyPHINode(PHINode *PN, ArrayRef<Value *> IncomingValues,
// If all of the PHI's incoming values are the same then replace the PHI node
// with the common value.
Value *CommonValue = nullptr;
+ bool HasPoisonInput = false;
bool HasUndefInput = false;
for (Value *Incoming : IncomingValues) {
// If the incoming value is the phi node itself, it can safely be skipped.
if (Incoming == PN)
continue;
+ if (isa<PoisonValue>(Incoming)) {
+ HasPoisonInput = true;
+ continue;
+ }
if (Q.isUndefValue(Incoming)) {
// Remember that we saw an undef value, but otherwise ignore them.
HasUndefInput = true;
@@ -5263,12 +5268,13 @@ static Value *simplifyPHINode(PHINode *PN, ArrayRef<Value *> IncomingValues,
CommonValue = Incoming;
}
- // If CommonValue is null then all of the incoming values were either undef or
- // equal to the phi node itself.
+ // If CommonValue is null then all of the incoming values were either undef,
+ // poison or equal to the phi node itself.
if (!CommonValue)
- return UndefValue::get(PN->getType());
+ return HasUndefInput ? UndefValue::get(PN->getType())
+ : PoisonValue::get(PN->getType());
- if (HasUndefInput) {
+ if (HasPoisonInput || HasUndefInput) {
// If we have a PHI node like phi(X, undef, X), where X is defined by some
// instruction, we cannot return X as the result of the PHI node unless it
// dominates the PHI block.
diff --git a/llvm/test/Transforms/InstCombine/shift.ll b/llvm/test/Transforms/InstCombine/shift.ll
index 0700d7a62ee15..f0bfd0171b265 100644
--- a/llvm/test/Transforms/InstCombine/shift.ll
+++ b/llvm/test/Transforms/InstCombine/shift.ll
@@ -1151,7 +1151,7 @@ define void @test61(i128 %arg, i1 %c1, i1 %c2, i1 %c3, i1 %c4) {
; CHECK: bb7:
; CHECK-NEXT: br i1 [[C3:%.*]], label [[BB8]], label [[BB2]]
; CHECK: bb8:
-; CHECK-NEXT: br i1 undef, label [[BB11:%.*]], label [[BB12]]
+; CHECK-NEXT: br i1 poison, label [[BB11:%.*]], label [[BB12]]
; CHECK: bb11:
; CHECK-NEXT: br i1 [[C4:%.*]], label [[BB1]], label [[BB12]]
; CHECK: bb12:
diff --git a/llvm/test/Transforms/InstSimplify/phi.ll b/llvm/test/Transforms/InstSimplify/phi.ll
index c97326ea05137..5cc3fecb129f4 100644
--- a/llvm/test/Transforms/InstSimplify/phi.ll
+++ b/llvm/test/Transforms/InstSimplify/phi.ll
@@ -141,7 +141,7 @@ define i8 @only_poison(i1 %cond) {
; CHECK: B:
; CHECK-NEXT: br label [[EXIT]]
; CHECK: EXIT:
-; CHECK-NEXT: ret i8 undef
+; CHECK-NEXT: ret i8 poison
;
br i1 %cond, label %A, label %B
A:
diff --git a/llvm/test/Transforms/LoopDeletion/update-scev.ll b/llvm/test/Transforms/LoopDeletion/update-scev.ll
index 64c7ca9fc4e37..3a4466496a1ed 100644
--- a/llvm/test/Transforms/LoopDeletion/update-scev.ll
+++ b/llvm/test/Transforms/LoopDeletion/update-scev.ll
@@ -66,7 +66,7 @@ define void @test2(ptr %bx, i64 %by) local_unnamed_addr align 2 {
; SCEV-EXPRS-LABEL: test2
; SCEV-EXPRS: %inc.lcssa.1 = phi i64 [ poison, %for.body7.preheader.1 ]
-; SCEV-EXPRS-NEXT: --> undef
+; SCEV-EXPRS-NEXT: --> poison
entry:
%cmp = icmp sgt i64 %by, 0
br label %for.cond.preheader
More information about the llvm-commits
mailing list