Skip to content

Commit c5aa983

Browse files
committed
[InstSimplify] Fold all poison phi to poison instead of undef
1 parent c436649 commit c5aa983

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5248,11 +5248,16 @@ static Value *simplifyPHINode(PHINode *PN, ArrayRef<Value *> IncomingValues,
52485248
// If all of the PHI's incoming values are the same then replace the PHI node
52495249
// with the common value.
52505250
Value *CommonValue = nullptr;
5251+
bool HasPoisonInput = false;
52515252
bool HasUndefInput = false;
52525253
for (Value *Incoming : IncomingValues) {
52535254
// If the incoming value is the phi node itself, it can safely be skipped.
52545255
if (Incoming == PN)
52555256
continue;
5257+
if (isa<PoisonValue>(Incoming)) {
5258+
HasPoisonInput = true;
5259+
continue;
5260+
}
52565261
if (Q.isUndefValue(Incoming)) {
52575262
// Remember that we saw an undef value, but otherwise ignore them.
52585263
HasUndefInput = true;
@@ -5263,12 +5268,13 @@ static Value *simplifyPHINode(PHINode *PN, ArrayRef<Value *> IncomingValues,
52635268
CommonValue = Incoming;
52645269
}
52655270

5266-
// If CommonValue is null then all of the incoming values were either undef or
5267-
// equal to the phi node itself.
5271+
// If CommonValue is null then all of the incoming values were either undef,
5272+
// poison or equal to the phi node itself.
52685273
if (!CommonValue)
5269-
return UndefValue::get(PN->getType());
5274+
return HasUndefInput ? UndefValue::get(PN->getType())
5275+
: PoisonValue::get(PN->getType());
52705276

5271-
if (HasUndefInput) {
5277+
if (HasPoisonInput || HasUndefInput) {
52725278
// If we have a PHI node like phi(X, undef, X), where X is defined by some
52735279
// instruction, we cannot return X as the result of the PHI node unless it
52745280
// dominates the PHI block.

llvm/test/Transforms/InstCombine/shift.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ define void @test61(i128 %arg, i1 %c1, i1 %c2, i1 %c3, i1 %c4) {
11511151
; CHECK: bb7:
11521152
; CHECK-NEXT: br i1 [[C3:%.*]], label [[BB8]], label [[BB2]]
11531153
; CHECK: bb8:
1154-
; CHECK-NEXT: br i1 undef, label [[BB11:%.*]], label [[BB12]]
1154+
; CHECK-NEXT: br i1 poison, label [[BB11:%.*]], label [[BB12]]
11551155
; CHECK: bb11:
11561156
; CHECK-NEXT: br i1 [[C4:%.*]], label [[BB1]], label [[BB12]]
11571157
; CHECK: bb12:

llvm/test/Transforms/InstSimplify/phi.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ define i8 @only_poison(i1 %cond) {
141141
; CHECK: B:
142142
; CHECK-NEXT: br label [[EXIT]]
143143
; CHECK: EXIT:
144-
; CHECK-NEXT: ret i8 undef
144+
; CHECK-NEXT: ret i8 poison
145145
;
146146
br i1 %cond, label %A, label %B
147147
A:

llvm/test/Transforms/LoopDeletion/update-scev.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ define void @test2(ptr %bx, i64 %by) local_unnamed_addr align 2 {
6666

6767
; SCEV-EXPRS-LABEL: test2
6868
; SCEV-EXPRS: %inc.lcssa.1 = phi i64 [ poison, %for.body7.preheader.1 ]
69-
; SCEV-EXPRS-NEXT: --> undef
69+
; SCEV-EXPRS-NEXT: --> poison
7070
entry:
7171
%cmp = icmp sgt i64 %by, 0
7272
br label %for.cond.preheader

0 commit comments

Comments
 (0)