Skip to content

Commit 89d123d

Browse files
committed
[InstCombine] Support well-defined recurrences in isGuaranteedNotToBeUndefOrPoison
This function currently doesn't detect well-defined recurrences that can't produce undef or poison. This prevents instcombine from pushing freezes through GEPs to the ptr which may be undef or poison, when the offset is a well-defined recurrence, as the tests added in #145541 demonstrate. This patch fixes this by pulling existing code from foldFreezeIntoRecurrence in instcombine, which can detect whether a PHI produces undef/poison, so it can be reused by isGuaranteedNotToBeUndefOrPoison in ValueTracking.
1 parent ef51514 commit 89d123d

File tree

9 files changed

+111
-80
lines changed

9 files changed

+111
-80
lines changed

llvm/include/llvm/Analysis/ValueTracking.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,14 @@ LLVM_ABI bool canCreatePoison(const Operator *Op,
773773
/// impliesPoison returns true.
774774
LLVM_ABI bool impliesPoison(const Value *ValAssumedPoison, const Value *V);
775775

776+
/// Detect if PN is a recurrence with a start value and some number of backedge
777+
/// values. We'll check whether we can push the freeze through the backedge
778+
/// values (possibly dropping poison flags along the way) until we reach the
779+
/// phi again. In that case, we can move the freeze to the start value.
780+
LLVM_ABI Use *canFoldFreezeIntoRecurrence(
781+
PHINode *PN, DominatorTree *DT, bool &StartNeedsFreeze,
782+
SmallVectorImpl<Instruction *> *DropFlags = nullptr);
783+
776784
/// Return true if this function can prove that V does not have undef bits
777785
/// and is never poison. If V is an aggregate value or vector, check whether
778786
/// all elements (except padding) are not undef or poison.

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7569,6 +7569,66 @@ bool llvm::impliesPoison(const Value *ValAssumedPoison, const Value *V) {
75697569

75707570
static bool programUndefinedIfUndefOrPoison(const Value *V, bool PoisonOnly);
75717571

7572+
Use *llvm::canFoldFreezeIntoRecurrence(
7573+
PHINode *PN, DominatorTree *DT, bool &StartNeedsFreeze,
7574+
SmallVectorImpl<Instruction *> *DropFlags) {
7575+
// Detect whether this is a recurrence with a start value and some number of
7576+
// backedge values. We'll check whether we can push the freeze through the
7577+
// backedge values (possibly dropping poison flags along the way) until we
7578+
// reach the phi again. In that case, we can move the freeze to the start
7579+
// value.
7580+
Use *StartU = nullptr;
7581+
SmallVector<Value *> Worklist;
7582+
for (Use &U : PN->incoming_values()) {
7583+
if (DT && DT->dominates(PN->getParent(), PN->getIncomingBlock(U))) {
7584+
// Add backedge value to worklist.
7585+
Worklist.push_back(U.get());
7586+
continue;
7587+
}
7588+
7589+
// Don't bother handling multiple start values.
7590+
if (StartU)
7591+
return nullptr;
7592+
StartU = &U;
7593+
}
7594+
7595+
if (!StartU || Worklist.empty())
7596+
return nullptr; // Not a recurrence.
7597+
7598+
Value *StartV = StartU->get();
7599+
BasicBlock *StartBB = PN->getIncomingBlock(*StartU);
7600+
StartNeedsFreeze = !isGuaranteedNotToBeUndefOrPoison(StartV);
7601+
// We can't insert freeze if the start value is the result of the
7602+
// terminator (e.g. an invoke).
7603+
if (StartNeedsFreeze && StartBB->getTerminator() == StartV)
7604+
return nullptr;
7605+
7606+
SmallPtrSet<Value *, 32> Visited;
7607+
while (!Worklist.empty()) {
7608+
Value *V = Worklist.pop_back_val();
7609+
if (!Visited.insert(V).second)
7610+
continue;
7611+
7612+
if (Visited.size() > 32)
7613+
return nullptr; // Limit the total number of values we inspect.
7614+
7615+
// Assume that PN is non-poison, because it will be after the transform.
7616+
if (V == PN || isGuaranteedNotToBeUndefOrPoison(V))
7617+
continue;
7618+
7619+
Instruction *I = dyn_cast<Instruction>(V);
7620+
if (!I || canCreateUndefOrPoison(cast<Operator>(I),
7621+
/*ConsiderFlagsAndMetadata*/ false))
7622+
return nullptr;
7623+
7624+
if (DropFlags)
7625+
DropFlags->push_back(I);
7626+
append_range(Worklist, I->operands());
7627+
}
7628+
7629+
return StartU;
7630+
}
7631+
75727632
static bool isGuaranteedNotToBeUndefOrPoison(
75737633
const Value *V, AssumptionCache *AC, const Instruction *CtxI,
75747634
const DominatorTree *DT, unsigned Depth, UndefPoisonKind Kind) {
@@ -7657,6 +7717,13 @@ static bool isGuaranteedNotToBeUndefOrPoison(
76577717
}
76587718
if (IsWellDefined)
76597719
return true;
7720+
7721+
bool StartNeedsFreeze;
7722+
if (canFoldFreezeIntoRecurrence(const_cast<PHINode *>(PN),
7723+
const_cast<DominatorTree *>(DT),
7724+
StartNeedsFreeze) &&
7725+
!StartNeedsFreeze)
7726+
return true;
76607727
} else if (!::canCreateUndefOrPoison(Opr, Kind,
76617728
/*ConsiderFlagsAndMetadata*/ true) &&
76627729
all_of(Opr->operands(), OpCheck))

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4933,7 +4933,8 @@ InstCombinerImpl::pushFreezeToPreventPoisonFromPropagating(FreezeInst &OrigFI) {
49334933
// poison.
49344934
Value *MaybePoisonOperand = nullptr;
49354935
for (Value *V : OrigOpInst->operands()) {
4936-
if (isa<MetadataAsValue>(V) || isGuaranteedNotToBeUndefOrPoison(V) ||
4936+
if (isa<MetadataAsValue>(V) ||
4937+
isGuaranteedNotToBeUndefOrPoison(V, &AC, &OrigFI, &DT) ||
49374938
// Treat identical operands as a single operand.
49384939
(MaybePoisonOperand && MaybePoisonOperand == V))
49394940
continue;
@@ -4959,64 +4960,19 @@ InstCombinerImpl::pushFreezeToPreventPoisonFromPropagating(FreezeInst &OrigFI) {
49594960

49604961
Instruction *InstCombinerImpl::foldFreezeIntoRecurrence(FreezeInst &FI,
49614962
PHINode *PN) {
4962-
// Detect whether this is a recurrence with a start value and some number of
4963-
// backedge values. We'll check whether we can push the freeze through the
4964-
// backedge values (possibly dropping poison flags along the way) until we
4965-
// reach the phi again. In that case, we can move the freeze to the start
4966-
// value.
4967-
Use *StartU = nullptr;
4968-
SmallVector<Value *> Worklist;
4969-
for (Use &U : PN->incoming_values()) {
4970-
if (DT.dominates(PN->getParent(), PN->getIncomingBlock(U))) {
4971-
// Add backedge value to worklist.
4972-
Worklist.push_back(U.get());
4973-
continue;
4974-
}
4975-
4976-
// Don't bother handling multiple start values.
4977-
if (StartU)
4978-
return nullptr;
4979-
StartU = &U;
4980-
}
4981-
4982-
if (!StartU || Worklist.empty())
4983-
return nullptr; // Not a recurrence.
4984-
4985-
Value *StartV = StartU->get();
4986-
BasicBlock *StartBB = PN->getIncomingBlock(*StartU);
4987-
bool StartNeedsFreeze = !isGuaranteedNotToBeUndefOrPoison(StartV);
4988-
// We can't insert freeze if the start value is the result of the
4989-
// terminator (e.g. an invoke).
4990-
if (StartNeedsFreeze && StartBB->getTerminator() == StartV)
4991-
return nullptr;
4992-
4993-
SmallPtrSet<Value *, 32> Visited;
4963+
bool StartNeedsFreeze;
49944964
SmallVector<Instruction *> DropFlags;
4995-
while (!Worklist.empty()) {
4996-
Value *V = Worklist.pop_back_val();
4997-
if (!Visited.insert(V).second)
4998-
continue;
4999-
5000-
if (Visited.size() > 32)
5001-
return nullptr; // Limit the total number of values we inspect.
5002-
5003-
// Assume that PN is non-poison, because it will be after the transform.
5004-
if (V == PN || isGuaranteedNotToBeUndefOrPoison(V))
5005-
continue;
5006-
5007-
Instruction *I = dyn_cast<Instruction>(V);
5008-
if (!I || canCreateUndefOrPoison(cast<Operator>(I),
5009-
/*ConsiderFlagsAndMetadata*/ false))
5010-
return nullptr;
5011-
5012-
DropFlags.push_back(I);
5013-
append_range(Worklist, I->operands());
5014-
}
4965+
Use *StartU =
4966+
canFoldFreezeIntoRecurrence(PN, &DT, StartNeedsFreeze, &DropFlags);
4967+
if (!StartU)
4968+
return nullptr;
50154969

50164970
for (Instruction *I : DropFlags)
50174971
I->dropPoisonGeneratingAnnotations();
50184972

50194973
if (StartNeedsFreeze) {
4974+
Value *StartV = StartU->get();
4975+
BasicBlock *StartBB = PN->getIncomingBlock(*StartU);
50204976
Builder.SetInsertPoint(StartBB->getTerminator());
50214977
Value *FrozenStartV = Builder.CreateFreeze(StartV,
50224978
StartV->getName() + ".fr");

llvm/test/Transforms/Attributor/dereferenceable-1.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ define void @deref_phi_growing(ptr dereferenceable(4000) %a) {
9595
; CHECK: for.cond:
9696
; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
9797
; CHECK-NEXT: [[A_ADDR_0:%.*]] = phi ptr [ [[A]], [[ENTRY]] ], [ [[INCDEC_PTR:%.*]], [[FOR_INC]] ]
98-
; CHECK-NEXT: call void @deref_phi_user(ptr nonnull [[A_ADDR_0]])
98+
; CHECK-NEXT: call void @deref_phi_user(ptr noundef nonnull [[A_ADDR_0]])
9999
; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[A_ADDR_0]], align 4
100100
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_0]], [[VAL]]
101101
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_COND_CLEANUP:%.*]]
@@ -146,7 +146,7 @@ define void @deref_phi_shrinking(ptr dereferenceable(4000) %a) {
146146
; CHECK: for.cond:
147147
; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
148148
; CHECK-NEXT: [[A_ADDR_0:%.*]] = phi ptr [ [[A]], [[ENTRY]] ], [ [[INCDEC_PTR:%.*]], [[FOR_INC]] ]
149-
; CHECK-NEXT: call void @deref_phi_user(ptr nonnull [[A_ADDR_0]])
149+
; CHECK-NEXT: call void @deref_phi_user(ptr noundef nonnull [[A_ADDR_0]])
150150
; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[A_ADDR_0]], align 4
151151
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_0]], [[VAL]]
152152
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_COND_CLEANUP:%.*]]

llvm/test/Transforms/Attributor/value-simplify.ll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ define internal ptr @test_byval2(ptr byval(%struct.X) %a) {
626626
; CHECK-NEXT: [[A_PRIV:%.*]] = alloca [[STRUCT_X:%.*]], align 8
627627
; CHECK-NEXT: store ptr [[TMP0]], ptr [[A_PRIV]], align 8
628628
; CHECK-NEXT: call void @sync()
629-
; CHECK-NEXT: [[L:%.*]] = load ptr, ptr [[A_PRIV]], align 8
629+
; CHECK-NEXT: [[L:%.*]] = load ptr, ptr [[A_PRIV]], align 8, !invariant.load [[META0:![0-9]+]]
630630
; CHECK-NEXT: ret ptr [[L]]
631631
;
632632
call void @sync()
@@ -1359,7 +1359,7 @@ define internal i32 @ret_speculatable_expr(ptr %mem, i32 %a2) {
13591359
; CGSCC-SAME: (i32 [[TMP0:%.*]]) #[[ATTR1]] {
13601360
; CGSCC-NEXT: [[MEM_PRIV:%.*]] = alloca i32, align 4
13611361
; CGSCC-NEXT: store i32 [[TMP0]], ptr [[MEM_PRIV]], align 4
1362-
; CGSCC-NEXT: [[L:%.*]] = load i32, ptr [[MEM_PRIV]], align 4
1362+
; CGSCC-NEXT: [[L:%.*]] = load i32, ptr [[MEM_PRIV]], align 4, !invariant.load [[META0]]
13631363
; CGSCC-NEXT: [[MUL:%.*]] = mul i32 [[L]], 13
13641364
; CGSCC-NEXT: [[ADD:%.*]] = add i32 [[MUL]], 7
13651365
; CGSCC-NEXT: ret i32 [[ADD]]
@@ -1709,3 +1709,7 @@ define i32 @readExtInitZeroInit() {
17091709
; CGSCC: attributes #[[ATTR17]] = { nosync }
17101710
; CGSCC: attributes #[[ATTR18]] = { nounwind }
17111711
;.
1712+
; TUNIT: [[META0]] = !{}
1713+
;.
1714+
; CGSCC: [[META0]] = !{}
1715+
;.

llvm/test/Transforms/InstCombine/freeze-landingpad.ll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,18 @@ define i32 @propagate_freeze_in_landingpad() personality ptr null {
99
; CHECK: invoke.bb1:
1010
; CHECK-NEXT: [[X:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[NORMAL_RETURN:%.*]] ]
1111
; CHECK-NEXT: [[RES0:%.*]] = invoke i32 @foo()
12-
; CHECK-NEXT: to label [[INVOKE_BB2:%.*]] unwind label [[EXCEPTIONAL_RETURN:%.*]]
12+
; CHECK-NEXT: to label [[INVOKE_BB2:%.*]] unwind label [[EXCEPTIONAL_RETURN:%.*]]
1313
; CHECK: invoke.bb2:
1414
; CHECK-NEXT: [[RES1:%.*]] = invoke i32 @foo()
15-
; CHECK-NEXT: to label [[NORMAL_RETURN]] unwind label [[EXCEPTIONAL_RETURN]]
15+
; CHECK-NEXT: to label [[NORMAL_RETURN]] unwind label [[EXCEPTIONAL_RETURN]]
1616
; CHECK: normal_return:
1717
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[X]], 1
1818
; CHECK-NEXT: br label [[INVOKE_BB1]]
1919
; CHECK: exceptional_return:
2020
; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[X]], [[INVOKE_BB1]] ], [ 0, [[INVOKE_BB2]] ]
2121
; CHECK-NEXT: [[LANDING_PAD:%.*]] = landingpad { ptr, i32 }
22-
; CHECK-NEXT: cleanup
23-
; CHECK-NEXT: [[FR:%.*]] = freeze i32 [[PHI]]
24-
; CHECK-NEXT: [[RES:%.*]] = shl i32 [[FR]], 1
22+
; CHECK-NEXT: cleanup
23+
; CHECK-NEXT: [[RES:%.*]] = shl nuw i32 [[PHI]], 1
2524
; CHECK-NEXT: ret i32 [[RES]]
2625
;
2726
entry:

llvm/test/Transforms/InstCombine/freeze.ll

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -889,17 +889,17 @@ exit: ; preds = %loop
889889
}
890890

891891
; The recurrence for the GEP offset can't produce poison so the freeze should
892-
; be pushed through to the ptr, but this is not currently supported.
892+
; be pushed through to the ptr.
893893
define void @fold_phi_gep_phi_offset(ptr %init, ptr %end, i64 noundef %n) {
894894
; CHECK-LABEL: @fold_phi_gep_phi_offset(
895895
; CHECK-NEXT: entry:
896+
; CHECK-NEXT: [[INIT:%.*]] = freeze ptr [[INIT1:%.*]]
896897
; CHECK-NEXT: br label [[LOOP:%.*]]
897898
; CHECK: loop:
898-
; CHECK-NEXT: [[I:%.*]] = phi ptr [ [[INIT:%.*]], [[ENTRY:%.*]] ], [ [[I_NEXT_FR:%.*]], [[LOOP]] ]
899+
; CHECK-NEXT: [[I:%.*]] = phi ptr [ [[INIT]], [[ENTRY:%.*]] ], [ [[I_NEXT_FR:%.*]], [[LOOP]] ]
899900
; CHECK-NEXT: [[OFF:%.*]] = phi i64 [ [[N:%.*]], [[ENTRY]] ], [ [[OFF_NEXT:%.*]], [[LOOP]] ]
900901
; CHECK-NEXT: [[OFF_NEXT]] = shl i64 [[OFF]], 3
901-
; CHECK-NEXT: [[I_NEXT:%.*]] = getelementptr i8, ptr [[I]], i64 [[OFF_NEXT]]
902-
; CHECK-NEXT: [[I_NEXT_FR]] = freeze ptr [[I_NEXT]]
902+
; CHECK-NEXT: [[I_NEXT_FR]] = getelementptr i8, ptr [[I]], i64 [[OFF_NEXT]]
903903
; CHECK-NEXT: [[COND:%.*]] = icmp eq ptr [[I_NEXT_FR]], [[END:%.*]]
904904
; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT:%.*]]
905905
; CHECK: exit:
@@ -921,18 +921,18 @@ exit: ; preds = %loop
921921
ret void
922922
}
923923

924-
; Offset is still guaranteed not to be poison, so the freeze could be moved
925-
; here if we strip inbounds from the GEP, but this is not currently supported.
924+
; Offset is still guaranteed not to be poison, so the freeze can be moved
925+
; here if we strip inbounds from the GEP.
926926
define void @fold_phi_gep_inbounds_phi_offset(ptr %init, ptr %end, i64 noundef %n) {
927927
; CHECK-LABEL: @fold_phi_gep_inbounds_phi_offset(
928928
; CHECK-NEXT: entry:
929+
; CHECK-NEXT: [[INIT:%.*]] = freeze ptr [[INIT1:%.*]]
929930
; CHECK-NEXT: br label [[LOOP:%.*]]
930931
; CHECK: loop:
931-
; CHECK-NEXT: [[I:%.*]] = phi ptr [ [[INIT:%.*]], [[ENTRY:%.*]] ], [ [[I_NEXT_FR:%.*]], [[LOOP]] ]
932+
; CHECK-NEXT: [[I:%.*]] = phi ptr [ [[INIT]], [[ENTRY:%.*]] ], [ [[I_NEXT_FR:%.*]], [[LOOP]] ]
932933
; CHECK-NEXT: [[OFF:%.*]] = phi i64 [ [[N:%.*]], [[ENTRY]] ], [ [[OFF_NEXT:%.*]], [[LOOP]] ]
933934
; CHECK-NEXT: [[OFF_NEXT]] = shl i64 [[OFF]], 3
934-
; CHECK-NEXT: [[I_NEXT:%.*]] = getelementptr inbounds i8, ptr [[I]], i64 [[OFF_NEXT]]
935-
; CHECK-NEXT: [[I_NEXT_FR]] = freeze ptr [[I_NEXT]]
935+
; CHECK-NEXT: [[I_NEXT_FR]] = getelementptr i8, ptr [[I]], i64 [[OFF_NEXT]]
936936
; CHECK-NEXT: [[COND:%.*]] = icmp eq ptr [[I_NEXT_FR]], [[END:%.*]]
937937
; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT:%.*]]
938938
; CHECK: exit:
@@ -994,7 +994,7 @@ define void @fold_phi_multiple_insts(i32 %init, i32 %n) {
994994
; CHECK: loop:
995995
; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[INIT_FR]], [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
996996
; CHECK-NEXT: [[I_SQ:%.*]] = mul i32 [[I]], [[I]]
997-
; CHECK-NEXT: [[I_NEXT]] = add i32 [[I_SQ]], 1
997+
; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I_SQ]], 1
998998
; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[I_NEXT]], [[N:%.*]]
999999
; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT:%.*]]
10001000
; CHECK: exit:
@@ -1127,7 +1127,7 @@ define void @fold_phi_invoke_noundef_start_value(i32 %n) personality ptr undef {
11271127
; CHECK-NEXT: to label [[LOOP:%.*]] unwind label [[UNWIND:%.*]]
11281128
; CHECK: loop:
11291129
; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[INIT]], [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
1130-
; CHECK-NEXT: [[I_NEXT]] = add i32 [[I]], 1
1130+
; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I]], 1
11311131
; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[I_NEXT]], [[N:%.*]]
11321132
; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT:%.*]]
11331133
; CHECK: unwind:

llvm/test/Transforms/LoopUnroll/runtime-exit-phi-scev-invalidation.ll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ define void @pr56282() {
1616
; CHECK: outer.header:
1717
; CHECK-NEXT: [[OUTER_IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[OUTER_IV_NEXT:%.*]], [[INNER_2:%.*]] ]
1818
; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[OUTER_IV]], 1
19-
; CHECK-NEXT: [[TMP1:%.*]] = freeze i64 [[TMP0]]
20-
; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[TMP1]], -1
21-
; CHECK-NEXT: [[XTRAITER:%.*]] = and i64 [[TMP1]], 7
22-
; CHECK-NEXT: [[TMP3:%.*]] = icmp ult i64 [[TMP2]], 7
19+
; CHECK-NEXT: [[XTRAITER:%.*]] = and i64 [[TMP0]], 7
20+
; CHECK-NEXT: [[TMP3:%.*]] = icmp ult i64 [[OUTER_IV]], 7
2321
; CHECK-NEXT: br i1 [[TMP3]], label [[OUTER_MIDDLE_UNR_LCSSA:%.*]], label [[OUTER_HEADER_NEW:%.*]]
2422
; CHECK: outer.header.new:
25-
; CHECK-NEXT: [[UNROLL_ITER:%.*]] = sub i64 [[TMP1]], [[XTRAITER]]
23+
; CHECK-NEXT: [[UNROLL_ITER:%.*]] = sub i64 [[TMP0]], [[XTRAITER]]
2624
; CHECK-NEXT: br label [[INNER_1_HEADER:%.*]]
2725
; CHECK: inner.1.header:
2826
; CHECK-NEXT: [[INNER_1_IV:%.*]] = phi i64 [ 0, [[OUTER_HEADER_NEW]] ], [ [[INNER_1_IV_NEXT_7:%.*]], [[INNER_1_LATCH_7:%.*]] ]

llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-select.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,7 @@ define dso_local void @select_invariant_outer_loop(i1 noundef zeroext %cond, i32
662662
; CHECK-NEXT: [[I_021_US:%.*]] = phi i32 [ [[INC9_US:%.*]], [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND1_PREHEADER_US_PREHEADER]] ]
663663
; CHECK-NEXT: [[REM_US:%.*]] = and i32 [[I_021_US]], 1
664664
; CHECK-NEXT: [[CMP5_US:%.*]] = icmp eq i32 [[REM_US]], 0
665-
; CHECK-NEXT: [[CMP5_US_FR:%.*]] = freeze i1 [[CMP5_US]]
666-
; CHECK-NEXT: br i1 [[CMP5_US_FR]], label [[FOR_COND1_PREHEADER_US_SPLIT_US:%.*]], label [[FOR_COND1_PREHEADER_US_SPLIT:%.*]]
665+
; CHECK-NEXT: br i1 [[CMP5_US]], label [[FOR_COND1_PREHEADER_US_SPLIT_US:%.*]], label [[FOR_COND1_PREHEADER_US_SPLIT:%.*]]
667666
; CHECK: for.cond1.preheader.us.split.us:
668667
; CHECK-NEXT: br label [[FOR_BODY4_US_US:%.*]]
669668
; CHECK: for.body4.us.us:

0 commit comments

Comments
 (0)