Skip to content

Commit 022d15c

Browse files
committed
[LoopDeletion] match poison instead of undef for phi entries without an useful value
1 parent 7d33d47 commit 022d15c

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

llvm/lib/Transforms/Scalar/LoopDeletion.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ static bool canProveExitOnFirstIteration(Loop *L, DominatorTree &DT,
273273
if (LiveEdges.count({ Pred, BB })) {
274274
HasLivePreds = true;
275275
Value *Incoming = PN.getIncomingValueForBlock(Pred);
276-
// Skip undefs. If they are present, we can assume they are equal to
277-
// the non-undef input.
278-
if (isa<UndefValue>(Incoming))
276+
// Skip poison. If they are present, we can assume they are equal to
277+
// the non-poison input.
278+
if (isa<PoisonValue>(Incoming))
279279
continue;
280280
// Two inputs.
281281
if (OnlyInput && OnlyInput != Incoming)
@@ -284,8 +284,8 @@ static bool canProveExitOnFirstIteration(Loop *L, DominatorTree &DT,
284284
}
285285

286286
assert(HasLivePreds && "No live predecessors?");
287-
// If all incoming live value were undefs, return undef.
288-
return OnlyInput ? OnlyInput : UndefValue::get(PN.getType());
287+
// If all incoming live value were poison, return poison.
288+
return OnlyInput ? OnlyInput : PoisonValue::get(PN.getType());
289289
};
290290
DenseMap<Value *, Value *> FirstIterValue;
291291

llvm/test/Transforms/LoopDeletion/eval_first_iteration.ll

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,8 @@ failure:
717717
unreachable
718718
}
719719

720-
define i32 @test_multiple_pred_undef_1(i1 %cond, i1 %cond2) {
721-
; CHECK-LABEL: @test_multiple_pred_undef_1(
720+
define i32 @test_multiple_pred_poison_1(i1 %cond, i1 %cond2) {
721+
; CHECK-LABEL: @test_multiple_pred_poison_1(
722722
; CHECK-NEXT: entry:
723723
; CHECK-NEXT: br label [[LOOP:%.*]]
724724
; CHECK: loop:
@@ -739,7 +739,7 @@ define i32 @test_multiple_pred_undef_1(i1 %cond, i1 %cond2) {
739739
; CHECK: if.false.2:
740740
; CHECK-NEXT: br label [[BACKEDGE]]
741741
; CHECK: backedge:
742-
; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE_1]] ], [ 0, [[IF_FALSE_2]] ], [ [[SUB]], [[IF_TRUE_1]] ], [ undef, [[IF_TRUE_2]] ]
742+
; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE_1]] ], [ 0, [[IF_FALSE_2]] ], [ [[SUB]], [[IF_TRUE_1]] ], [ poison, [[IF_TRUE_2]] ]
743743
; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
744744
; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
745745
; CHECK-NEXT: br label [[DONE:%.*]]
@@ -777,7 +777,7 @@ if.false.2:
777777
br label %backedge
778778

779779
backedge:
780-
%merge.phi = phi i32 [ 0, %if.false.1 ], [ 0, %if.false.2 ], [ %sub, %if.true.1 ], [ undef, %if.true.2 ]
780+
%merge.phi = phi i32 [ 0, %if.false.1 ], [ 0, %if.false.2 ], [ %sub, %if.true.1 ], [ poison, %if.true.2 ]
781781
%sum.next = add i32 %sum, %merge.phi
782782
%loop.cond = icmp ne i32 %sum.next, 4
783783
br i1 %loop.cond, label %loop, label %done
@@ -790,8 +790,8 @@ failure:
790790
unreachable
791791
}
792792

793-
define i32 @test_multiple_pred_undef_2(i1 %cond, i1 %cond2) {
794-
; CHECK-LABEL: @test_multiple_pred_undef_2(
793+
define i32 @test_multiple_pred_poison_2(i1 %cond, i1 %cond2) {
794+
; CHECK-LABEL: @test_multiple_pred_poison_2(
795795
; CHECK-NEXT: entry:
796796
; CHECK-NEXT: br label [[LOOP:%.*]]
797797
; CHECK: loop:
@@ -812,7 +812,7 @@ define i32 @test_multiple_pred_undef_2(i1 %cond, i1 %cond2) {
812812
; CHECK: if.false.2:
813813
; CHECK-NEXT: br label [[BACKEDGE]]
814814
; CHECK: backedge:
815-
; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE_1]] ], [ 0, [[IF_FALSE_2]] ], [ undef, [[IF_TRUE_1]] ], [ [[SUB]], [[IF_TRUE_2]] ]
815+
; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE_1]] ], [ 0, [[IF_FALSE_2]] ], [ poison, [[IF_TRUE_1]] ], [ [[SUB]], [[IF_TRUE_2]] ]
816816
; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
817817
; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
818818
; CHECK-NEXT: br label [[DONE:%.*]]
@@ -850,7 +850,7 @@ if.false.2:
850850
br label %backedge
851851

852852
backedge:
853-
%merge.phi = phi i32 [ 0, %if.false.1 ], [ 0, %if.false.2 ], [ undef, %if.true.1 ], [ %sub, %if.true.2 ]
853+
%merge.phi = phi i32 [ 0, %if.false.1 ], [ 0, %if.false.2 ], [ poison, %if.true.1 ], [ %sub, %if.true.2 ]
854854
%sum.next = add i32 %sum, %merge.phi
855855
%loop.cond = icmp ne i32 %sum.next, 4
856856
br i1 %loop.cond, label %loop, label %done
@@ -863,8 +863,8 @@ failure:
863863
unreachable
864864
}
865865

866-
define i32 @test_multiple_pred_undef_3(i1 %cond, i1 %cond2) {
867-
; CHECK-LABEL: @test_multiple_pred_undef_3(
866+
define i32 @test_multiple_pred_poison_3(i1 %cond, i1 %cond2) {
867+
; CHECK-LABEL: @test_multiple_pred_poison_3(
868868
; CHECK-NEXT: entry:
869869
; CHECK-NEXT: br label [[LOOP:%.*]]
870870
; CHECK: loop:
@@ -885,7 +885,7 @@ define i32 @test_multiple_pred_undef_3(i1 %cond, i1 %cond2) {
885885
; CHECK: if.false.2:
886886
; CHECK-NEXT: br label [[BACKEDGE]]
887887
; CHECK: backedge:
888-
; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE_1]] ], [ 0, [[IF_FALSE_2]] ], [ undef, [[IF_TRUE_1]] ], [ undef, [[IF_TRUE_2]] ]
888+
; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE_1]] ], [ 0, [[IF_FALSE_2]] ], [ poison, [[IF_TRUE_1]] ], [ poison, [[IF_TRUE_2]] ]
889889
; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
890890
; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
891891
; CHECK-NEXT: br label [[DONE:%.*]]
@@ -923,7 +923,7 @@ if.false.2:
923923
br label %backedge
924924

925925
backedge:
926-
%merge.phi = phi i32 [ 0, %if.false.1 ], [ 0, %if.false.2 ], [ undef, %if.true.1 ], [ undef, %if.true.2 ]
926+
%merge.phi = phi i32 [ 0, %if.false.1 ], [ 0, %if.false.2 ], [ poison, %if.true.1 ], [ poison, %if.true.2 ]
927927
%sum.next = add i32 %sum, %merge.phi
928928
%loop.cond = icmp ne i32 %sum.next, 4
929929
br i1 %loop.cond, label %loop, label %done

0 commit comments

Comments
 (0)