Skip to content

Commit b46c085

Browse files
committed
[NFCI] SCEVExpander: emit intrinsics for integral {u,s}{min,max} SCEV expressions
These intrinsics, not the icmp+select are the canonical form nowadays, so we might as well directly emit them. This should not cause any regressions, but if it does, then then they would needed to be fixed regardless. Note that this doesn't deal with `SCEVExpander::isHighCostExpansion()`, but that is a pessimization, not a correctness issue. Additionally, the non-intrinsic form has issues with undef, see https://reviews.llvm.org/D88287#2587863
1 parent f0904a6 commit b46c085

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1392
-1470
lines changed

llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,8 +1715,14 @@ Value *SCEVExpander::visitSMaxExpr(const SCEVSMaxExpr *S) {
17151715
LHS = InsertNoopCastOfTo(LHS, Ty);
17161716
}
17171717
Value *RHS = expandCodeForImpl(S->getOperand(i), Ty, false);
1718-
Value *ICmp = Builder.CreateICmpSGT(LHS, RHS);
1719-
Value *Sel = Builder.CreateSelect(ICmp, LHS, RHS, "smax");
1718+
Value *Sel;
1719+
if (Ty->isIntegerTy())
1720+
Sel = Builder.CreateIntrinsic(Intrinsic::smax, {Ty}, {LHS, RHS},
1721+
/*FMFSource=*/nullptr, "smax");
1722+
else {
1723+
Value *ICmp = Builder.CreateICmpSGT(LHS, RHS);
1724+
Sel = Builder.CreateSelect(ICmp, LHS, RHS, "smax");
1725+
}
17201726
LHS = Sel;
17211727
}
17221728
// In the case of mixed integer and pointer types, cast the
@@ -1738,8 +1744,14 @@ Value *SCEVExpander::visitUMaxExpr(const SCEVUMaxExpr *S) {
17381744
LHS = InsertNoopCastOfTo(LHS, Ty);
17391745
}
17401746
Value *RHS = expandCodeForImpl(S->getOperand(i), Ty, false);
1741-
Value *ICmp = Builder.CreateICmpUGT(LHS, RHS);
1742-
Value *Sel = Builder.CreateSelect(ICmp, LHS, RHS, "umax");
1747+
Value *Sel;
1748+
if (Ty->isIntegerTy())
1749+
Sel = Builder.CreateIntrinsic(Intrinsic::umax, {Ty}, {LHS, RHS},
1750+
/*FMFSource=*/nullptr, "umax");
1751+
else {
1752+
Value *ICmp = Builder.CreateICmpUGT(LHS, RHS);
1753+
Sel = Builder.CreateSelect(ICmp, LHS, RHS, "umax");
1754+
}
17431755
LHS = Sel;
17441756
}
17451757
// In the case of mixed integer and pointer types, cast the
@@ -1761,8 +1773,14 @@ Value *SCEVExpander::visitSMinExpr(const SCEVSMinExpr *S) {
17611773
LHS = InsertNoopCastOfTo(LHS, Ty);
17621774
}
17631775
Value *RHS = expandCodeForImpl(S->getOperand(i), Ty, false);
1764-
Value *ICmp = Builder.CreateICmpSLT(LHS, RHS);
1765-
Value *Sel = Builder.CreateSelect(ICmp, LHS, RHS, "smin");
1776+
Value *Sel;
1777+
if (Ty->isIntegerTy())
1778+
Sel = Builder.CreateIntrinsic(Intrinsic::smin, {Ty}, {LHS, RHS},
1779+
/*FMFSource=*/nullptr, "smin");
1780+
else {
1781+
Value *ICmp = Builder.CreateICmpSLT(LHS, RHS);
1782+
Sel = Builder.CreateSelect(ICmp, LHS, RHS, "smin");
1783+
}
17661784
LHS = Sel;
17671785
}
17681786
// In the case of mixed integer and pointer types, cast the
@@ -1784,8 +1802,14 @@ Value *SCEVExpander::visitUMinExpr(const SCEVUMinExpr *S) {
17841802
LHS = InsertNoopCastOfTo(LHS, Ty);
17851803
}
17861804
Value *RHS = expandCodeForImpl(S->getOperand(i), Ty, false);
1787-
Value *ICmp = Builder.CreateICmpULT(LHS, RHS);
1788-
Value *Sel = Builder.CreateSelect(ICmp, LHS, RHS, "umin");
1805+
Value *Sel;
1806+
if (Ty->isIntegerTy())
1807+
Sel = Builder.CreateIntrinsic(Intrinsic::umin, {Ty}, {LHS, RHS},
1808+
/*FMFSource=*/nullptr, "umin");
1809+
else {
1810+
Value *ICmp = Builder.CreateICmpULT(LHS, RHS);
1811+
Sel = Builder.CreateSelect(ICmp, LHS, RHS, "umin");
1812+
}
17891813
LHS = Sel;
17901814
}
17911815
// In the case of mixed integer and pointer types, cast the
@@ -2262,6 +2286,7 @@ template<typename T> static InstructionCost costAndCollectOperands(
22622286
case scUMaxExpr:
22632287
case scSMinExpr:
22642288
case scUMinExpr: {
2289+
// FIXME: should this ask the cost for Intrinsic's?
22652290
Cost += CmpSelCost(Instruction::ICmp, S->getNumOperands() - 1, 0, 1);
22662291
Cost += CmpSelCost(Instruction::Select, S->getNumOperands() - 1, 0, 2);
22672292
break;
Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
12
; RUN: opt < %s -indvars -adce -simplifycfg -S | FileCheck %s
23
; PR1598
34

4-
; CHECK: icmp s
5-
65
define i32 @f(i32 %a, i32 %b, i32 %x, i32 %y) {
6+
; CHECK-LABEL: @f(
7+
; CHECK-NEXT: entry:
8+
; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
9+
; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[X:%.*]], 1
10+
; CHECK-NEXT: [[SMAX:%.*]] = call i32 @llvm.smax.i32(i32 [[Y:%.*]], i32 [[TMP0]])
11+
; CHECK-NEXT: [[X_ADDR_1:%.*]] = select i1 [[TMP3]], i32 [[X]], i32 [[SMAX]]
12+
; CHECK-NEXT: ret i32 [[X_ADDR_1]]
13+
;
714
entry:
8-
%tmp3 = icmp eq i32 %a, %b ; <i1> [#uses=1]
9-
br i1 %tmp3, label %return, label %bb
15+
%tmp3 = icmp eq i32 %a, %b ; <i1> [#uses=1]
16+
br i1 %tmp3, label %return, label %bb
1017

1118
bb: ; preds = %bb, %entry
12-
%x_addr.0 = phi i32 [ %tmp6, %bb ], [ %x, %entry ] ; <i32> [#uses=1]
13-
%tmp6 = add i32 %x_addr.0, 1 ; <i32> [#uses=3]
14-
%tmp9 = icmp slt i32 %tmp6, %y ; <i1> [#uses=1]
15-
br i1 %tmp9, label %bb, label %return
19+
%x_addr.0 = phi i32 [ %tmp6, %bb ], [ %x, %entry ] ; <i32> [#uses=1]
20+
%tmp6 = add i32 %x_addr.0, 1 ; <i32> [#uses=3]
21+
%tmp9 = icmp slt i32 %tmp6, %y ; <i1> [#uses=1]
22+
br i1 %tmp9, label %bb, label %return
1623

1724
return: ; preds = %bb, %entry
18-
%x_addr.1 = phi i32 [ %x, %entry ], [ %tmp6, %bb ] ; <i32> [#uses=1]
19-
ret i32 %x_addr.1
25+
%x_addr.1 = phi i32 [ %x, %entry ], [ %tmp6, %bb ] ; <i32> [#uses=1]
26+
ret i32 %x_addr.1
2027
}

llvm/test/CodeGen/Thumb2/LowOverheadLoops/unpredload.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ define void @arm_cmplx_mag_squared_q15_mve(i16* %pSrc, i16* %pDst, i32 %blockSiz
55
; CHECK-LABEL: arm_cmplx_mag_squared_q15_mve:
66
; CHECK: @ %bb.0: @ %entry
77
; CHECK-NEXT: push {r7, lr}
8-
; CHECK-NEXT: subs.w r12, r2, #8
8+
; CHECK-NEXT: subs.w r3, r2, #8
99
; CHECK-NEXT: dlstp.16 lr, r2
1010
; CHECK-NEXT: .LBB0_1: @ %do.body
1111
; CHECK-NEXT: @ =>This Inner Loop Header: Depth=1

llvm/test/Transforms/HardwareLoops/ARM/fp-emulation.ll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
; CHECK-SOFT-NOT: call i32 @llvm.start.loop.iterations
66

77
; CHECK: entry:
8-
; CHECK-FP: [[CMP:%[^ ]+]] = icmp ugt i32 %n, 1
9-
; CHECK-FP: [[COUNT:%[^ ]+]] = select i1 [[CMP]], i32 %n, i32 1
8+
; CHECK-FP: [[COUNT:%[^ ]+]] = call i32 @llvm.umax.i32(i32 %n, i32 1)
109

1110
; CHECK: while.body.lr.ph:
1211
; CHECK-FP: [[START:%[^ ]+]] = call i32 @llvm.start.loop.iterations.i32(i32 [[COUNT]])
@@ -56,8 +55,7 @@ cleanup:
5655

5756
; CHECK-LABEL: test_fptoui
5857
; CHECK: entry:
59-
; CHECK-FP: [[CMP:%[^ ]+]] = icmp ugt i32 %n, 1
60-
; CHECK-FP: [[COUNT:%[^ ]+]] = select i1 [[CMP]], i32 %n, i32 1
58+
; CHECK-FP: [[COUNT:%[^ ]+]] = call i32 @llvm.umax.i32(i32 %n, i32 1)
6159
; CHECK-FP: while.body.lr.ph:
6260
; CHECK-FP: [[START:%[^ ]+]] = call i32 @llvm.start.loop.iterations.i32(i32 [[COUNT]])
6361
; CHECK-FP-NEXT: br label %while.body
@@ -108,8 +106,7 @@ cleanup:
108106

109107
; CHECK-LABEL: load_store_float
110108
; CHECK: entry:
111-
; CHECK: [[CMP:%[^ ]+]] = icmp ugt i32 %n, 1
112-
; CHECK: [[COUNT:%[^ ]+]] = select i1 [[CMP]], i32 %n, i32 1
109+
; CHECK: [[COUNT:%[^ ]+]] = call i32 @llvm.umax.i32(i32 %n, i32 1)
113110
; CHECK: while.body.lr.ph:
114111
; CHECK: [[START:%[^ ]+]] = call i32 @llvm.start.loop.iterations.i32(i32 [[COUNT]])
115112
; CHECK-NEXT: br label %while.body
@@ -158,8 +155,7 @@ cleanup:
158155
; CHECK-LABEL: fp_add
159156
; CHECK-SOFT-NOT: call i32 @llvm.start.loop.iterations
160157
; CHECK: entry:
161-
; CHECK-FP: [[CMP:%[^ ]+]] = icmp ugt i32 %n, 1
162-
; CHECK-FP: [[COUNT:%[^ ]+]] = select i1 [[CMP]], i32 %n, i32 1
158+
; CHECK-FP: [[COUNT:%[^ ]+]] = call i32 @llvm.umax.i32(i32 %n, i32 1)
163159
; CHECK: while.body.lr.ph:
164160
; CHECK-FP: [[START:%[^ ]+]] = call i32 @llvm.start.loop.iterations.i32(i32 [[COUNT]])
165161
; CHECK: br label %while.body

llvm/test/Transforms/HardwareLoops/ARM/simple-do.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ while.end:
146146

147147
; CHECK: entry:
148148
; CHECK: [[ROUND:%[^ ]+]] = add i32 %n, 1
149-
; CHECK: [[CMP:%[^ ]+]] = icmp slt i32 %n, 2
150-
; CHECK: [[SMIN:%[^ ]+]] = select i1 [[CMP]], i32 %n, i32 2
149+
; CHECK: [[SMIN:%[^ ]+]] = call i32 @llvm.smin.i32(i32 %n, i32 2)
151150
; CHECK: [[SUB:%[^ ]+]] = sub i32 [[ROUND]], [[SMIN]]
152151
; CHECK: [[HALVE:%[^ ]+]] = lshr i32 [[SUB]], 1
153152
; CHECK: [[COUNT:%[^ ]+]] = add nuw i32 [[HALVE]], 1

llvm/test/Transforms/HardwareLoops/loop-guards.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
; CHECK-LABEL: test1
88
; CHECK: entry:
9-
; CHECK: [[CMP:%[^ ]+]] = icmp ugt i32 %N, 2
10-
; CHECK: [[MAX:%[^ ]+]] = select i1 [[CMP]], i32 %N, i32 2
9+
; CHECK: [[MAX:%[^ ]+]] = call i32 @llvm.umax.i32(i32 %N, i32 2)
1110
; CHECK: [[COUNT:%[^ ]+]] = add i32 [[MAX]], -1
1211
; CHECK: br i1 %t1, label %do.body.preheader
1312
; CHECK: do.body.preheader:
@@ -60,8 +59,7 @@ if.end: ; preds = %do.body, %entry
6059

6160
; CHECK-LABEL: test3
6261
; CHECK: entry:
63-
; CHECK: [[CMP:%[^ ]+]] = icmp ugt i32 %N, 1
64-
; CHECK: [[COUNT:%[^ ]+]] = select i1 [[CMP]], i32 %N, i32 1
62+
; CHECK: [[COUNT:%[^ ]+]] = call i32 @llvm.umax.i32(i32 %N, i32 1)
6563
; CHECK: br i1 %brmerge.demorgan, label %do.body.preheader
6664
; CHECK: do.body.preheader:
6765
; CHECK-EXIT: call void @llvm.set.loop.iterations.i32(i32 [[COUNT]])

llvm/test/Transforms/IRCE/bad_expander.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ define void @test_03(i64* %p1, i64* %p2, i1 %maybe_exit) {
9090
; CHECK-NEXT: %num = load i64, i64* %p1, align 4
9191
; CHECK-NEXT: [[DIV:%[^ ]+]] = udiv i64 %num, 13
9292
; CHECK-NEXT: [[DIV_MINUS_1:%[^ ]+]] = add nsw i64 [[DIV]], -1
93-
; CHECK-NEXT: [[COMP1:%[^ ]+]] = icmp sgt i64 [[DIV_MINUS_1]], 0
94-
; CHECK-NEXT: %exit.mainloop.at = select i1 [[COMP1]], i64 [[DIV_MINUS_1]], i64 0
93+
; CHECK-NEXT: %exit.mainloop.at = call i64 @llvm.smax.i64(i64 [[DIV_MINUS_1]], i64 0)
9594
; CHECK-NEXT: [[COMP2:%[^ ]+]] = icmp slt i64 0, %exit.mainloop.at
9695
; CHECK-NEXT: br i1 [[COMP2]], label %loop.preheader, label %main.pseudo.exit
9796
; CHECK-NOT: preloop

llvm/test/Transforms/IRCE/clamp.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ preheader: ; preds = %entry
2828
; CHECK-NEXT: %length_gep.i146 = getelementptr inbounds i8, i8 addrspace(1)* undef, i64 8
2929
; CHECK-NEXT: %length_gep_typed.i147 = bitcast i8 addrspace(1)* undef to i32 addrspace(1)*
3030
; CHECK-NEXT: %tmp43 = icmp ult i64 %indvars.iv.next467, %tmp21
31-
; CHECK-NEXT: [[C0:%[^ ]+]] = icmp ugt i64 %tmp21, 1
32-
; CHECK-NEXT: %exit.mainloop.at = select i1 [[C0]], i64 %tmp21, i64 1
31+
; CHECK-NEXT: %exit.mainloop.at = call i64 @llvm.umax.i64(i64 %tmp21, i64 1)
3332
; CHECK-NEXT: [[C1:%[^ ]+]] = icmp ult i64 1, %exit.mainloop.at
3433
; CHECK-NEXT: br i1 [[C1]], label %loop.preheader, label %main.pseudo.exit
3534

llvm/test/Transforms/IRCE/conjunctive-checks.ll

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ define void @f_0(i32 *%arr, i32 *%a_len_ptr, i32 %n, i1* %cond_buf) {
66

77
; CHECK: loop.preheader:
88
; CHECK: [[len_sub:[^ ]+]] = add nsw i32 %len, -4
9-
; CHECK: [[exit_main_loop_at_hiclamp_cmp:[^ ]+]] = icmp slt i32 %n, [[len_sub]]
10-
; CHECK: [[exit_main_loop_at_hiclamp:[^ ]+]] = select i1 [[exit_main_loop_at_hiclamp_cmp]], i32 %n, i32 [[len_sub]]
11-
; CHECK: [[exit_main_loop_at_loclamp_cmp:[^ ]+]] = icmp sgt i32 [[exit_main_loop_at_hiclamp]], 0
12-
; CHECK: [[exit_main_loop_at_loclamp:[^ ]+]] = select i1 [[exit_main_loop_at_loclamp_cmp]], i32 [[exit_main_loop_at_hiclamp]], i32 0
9+
; CHECK: [[exit_main_loop_at_hiclamp:[^ ]+]] = call i32 @llvm.smin.i32(i32 %n, i32 [[len_sub]])
10+
; CHECK: [[exit_main_loop_at_loclamp:[^ ]+]] = call i32 @llvm.smax.i32(i32 [[exit_main_loop_at_hiclamp]], i32 0)
1311
; CHECK: [[enter_main_loop:[^ ]+]] = icmp slt i32 0, [[exit_main_loop_at_loclamp]]
1412
; CHECK: br i1 [[enter_main_loop]], label %[[loop_preheader2:[^ ,]+]], label %main.pseudo.exit
1513

@@ -56,12 +54,9 @@ define void @f_1(
5654
; CHECK-LABEL: @f_1(
5755

5856
; CHECK: loop.preheader:
59-
; CHECK: [[smax_len_cond:[^ ]+]] = icmp slt i32 %len.b, %len.a
60-
; CHECK: [[smax_len:[^ ]+]] = select i1 [[smax_len_cond]], i32 %len.b, i32 %len.a
61-
; CHECK: [[upper_limit_cond_loclamp:[^ ]+]] = icmp slt i32 [[smax_len]], %n
62-
; CHECK: [[upper_limit_loclamp:[^ ]+]] = select i1 [[upper_limit_cond_loclamp]], i32 [[smax_len]], i32 %n
63-
; CHECK: [[upper_limit_cmp:[^ ]+]] = icmp sgt i32 [[upper_limit_loclamp]], 0
64-
; CHECK: [[upper_limit:[^ ]+]] = select i1 [[upper_limit_cmp]], i32 [[upper_limit_loclamp]], i32 0
57+
; CHECK: [[smax_len:[^ ]+]] = call i32 @llvm.smin.i32(i32 %len.b, i32 %len.a)
58+
; CHECK: [[upper_limit_loclamp:[^ ]+]] = call i32 @llvm.smin.i32(i32 [[smax_len]], i32 %n)
59+
; CHECK: [[upper_limit:[^ ]+]] = call i32 @llvm.smax.i32(i32 [[upper_limit_loclamp]], i32 0)
6560

6661
entry:
6762
%len.a = load i32, i32* %a_len_ptr, !range !0

llvm/test/Transforms/IRCE/correct-loop-info.ll

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,38 @@ source_filename = "correct-loop-info.ll"
1313
define void @baz() personality i32* ()* @ham {
1414
; CHECK-LABEL: @baz(
1515
; CHECK-NEXT: bb:
16+
; CHECK-NEXT: [[EXIT_PRELOOP_AT:%.*]] = call i32 @llvm.smax.i32(i32 undef, i32 -1)
17+
; CHECK-NEXT: [[EXIT_MAINLOOP_AT:%.*]] = call i32 @llvm.smax.i32(i32 undef, i32 0)
1618
; CHECK-NEXT: br label [[OUTERHEADER:%.*]]
1719
; CHECK: outerheader:
1820
; CHECK-NEXT: [[TMP:%.*]] = icmp slt i32 undef, 84
1921
; CHECK-NEXT: br i1 [[TMP]], label [[BB2:%.*]], label [[BB16:%.*]]
2022
; CHECK: bb2:
21-
; CHECK-NEXT: br i1 false, label [[INNERHEADER_PRELOOP_PREHEADER:%.*]], label [[PRELOOP_PSEUDO_EXIT:%.*]]
23+
; CHECK-NEXT: [[TMP0:%.*]] = icmp slt i32 undef, [[EXIT_PRELOOP_AT]]
24+
; CHECK-NEXT: br i1 [[TMP0]], label [[INNERHEADER_PRELOOP_PREHEADER:%.*]], label [[PRELOOP_PSEUDO_EXIT:%.*]]
2225
; CHECK: innerheader.preloop.preheader:
2326
; CHECK-NEXT: br label [[INNERHEADER_PRELOOP:%.*]]
2427
; CHECK: mainloop:
25-
; CHECK-NEXT: [[TMP0:%.*]] = icmp slt i32 [[INDVAR_END:%.*]], 0
26-
; CHECK-NEXT: br i1 [[TMP0]], label [[INNERHEADER_PREHEADER:%.*]], label [[MAIN_PSEUDO_EXIT:%.*]]
28+
; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[INDVAR_END:%.*]], [[EXIT_MAINLOOP_AT]]
29+
; CHECK-NEXT: br i1 [[TMP1]], label [[INNERHEADER_PREHEADER:%.*]], label [[MAIN_PSEUDO_EXIT:%.*]]
2730
; CHECK: innerheader.preheader:
2831
; CHECK-NEXT: br label [[INNERHEADER:%.*]]
2932
; CHECK: innerheader:
3033
; CHECK-NEXT: [[TMP4:%.*]] = phi i32 [ [[TMP6:%.*]], [[BB8:%.*]] ], [ [[TMP4_PRELOOP_COPY:%.*]], [[INNERHEADER_PREHEADER]] ]
3134
; CHECK-NEXT: invoke void @pluto()
32-
; CHECK-NEXT: to label [[BB5:%.*]] unwind label %outer_exiting.loopexit.split-lp.loopexit.split-lp
35+
; CHECK-NEXT: to label [[BB5:%.*]] unwind label [[OUTER_EXITING_LOOPEXIT_SPLIT_LP_LOOPEXIT_SPLIT_LP:%.*]]
3336
; CHECK: bb5:
3437
; CHECK-NEXT: [[TMP6]] = add i32 [[TMP4]], 1
3538
; CHECK-NEXT: [[TMP7:%.*]] = icmp slt i32 [[TMP6]], 1
3639
; CHECK-NEXT: br i1 true, label [[BB8]], label [[EXIT3_LOOPEXIT5:%.*]]
3740
; CHECK: bb8:
3841
; CHECK-NEXT: [[TMP9:%.*]] = icmp slt i32 [[TMP6]], 84
39-
; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[TMP6]], 0
40-
; CHECK-NEXT: br i1 [[TMP1]], label [[INNERHEADER]], label [[MAIN_EXIT_SELECTOR:%.*]]
42+
; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i32 [[TMP6]], [[EXIT_MAINLOOP_AT]]
43+
; CHECK-NEXT: br i1 [[TMP2]], label [[INNERHEADER]], label [[MAIN_EXIT_SELECTOR:%.*]]
4144
; CHECK: main.exit.selector:
4245
; CHECK-NEXT: [[TMP6_LCSSA:%.*]] = phi i32 [ [[TMP6]], [[BB8]] ]
43-
; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i32 [[TMP6_LCSSA]], 84
44-
; CHECK-NEXT: br i1 [[TMP2]], label [[MAIN_PSEUDO_EXIT]], label [[BB13:%.*]]
46+
; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i32 [[TMP6_LCSSA]], 84
47+
; CHECK-NEXT: br i1 [[TMP3]], label [[MAIN_PSEUDO_EXIT]], label [[BB13:%.*]]
4548
; CHECK: main.pseudo.exit:
4649
; CHECK-NEXT: [[TMP4_COPY:%.*]] = phi i32 [ [[TMP4_PRELOOP_COPY]], [[MAINLOOP:%.*]] ], [ [[TMP6_LCSSA]], [[MAIN_EXIT_SELECTOR]] ]
4750
; CHECK-NEXT: [[INDVAR_END1:%.*]] = phi i32 [ [[INDVAR_END]], [[MAINLOOP]] ], [ [[TMP6_LCSSA]], [[MAIN_EXIT_SELECTOR]] ]
@@ -53,11 +56,11 @@ define void @baz() personality i32* ()* @ham {
5356
; CHECK: outer_exiting.loopexit.split-lp.loopexit:
5457
; CHECK-NEXT: [[LPAD_LOOPEXIT2:%.*]] = landingpad { i8*, i32 }
5558
; CHECK-NEXT: cleanup
56-
; CHECK-NEXT: br label %outer_exiting.loopexit.split-lp
59+
; CHECK-NEXT: br label [[OUTER_EXITING_LOOPEXIT_SPLIT_LP:%.*]]
5760
; CHECK: outer_exiting.loopexit.split-lp.loopexit.split-lp:
58-
; CHECK-NEXT: %lpad.loopexit.split-lp3 = landingpad { i8*, i32 }
61+
; CHECK-NEXT: [[LPAD_LOOPEXIT_SPLIT_LP3:%.*]] = landingpad { i8*, i32 }
5962
; CHECK-NEXT: cleanup
60-
; CHECK-NEXT: br label %outer_exiting.loopexit.split-lp
63+
; CHECK-NEXT: br label [[OUTER_EXITING_LOOPEXIT_SPLIT_LP]]
6164
; CHECK: outer_exiting.loopexit.split-lp:
6265
; CHECK-NEXT: br label [[OUTER_EXITING]]
6366
; CHECK: outer_exiting:
@@ -95,12 +98,12 @@ define void @baz() personality i32* ()* @ham {
9598
; CHECK-NEXT: br i1 [[TMP7_PRELOOP]], label [[BB8_PRELOOP]], label [[EXIT3_LOOPEXIT:%.*]]
9699
; CHECK: bb8.preloop:
97100
; CHECK-NEXT: [[TMP9_PRELOOP:%.*]] = icmp slt i32 [[TMP6_PRELOOP]], 84
98-
; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i32 [[TMP6_PRELOOP]], -1
99-
; CHECK-NEXT: br i1 [[TMP3]], label [[INNERHEADER_PRELOOP]], label [[PRELOOP_EXIT_SELECTOR:%.*]], !llvm.loop !0, !irce.loop.clone !5
101+
; CHECK-NEXT: [[TMP4:%.*]] = icmp slt i32 [[TMP6_PRELOOP]], [[EXIT_PRELOOP_AT]]
102+
; CHECK-NEXT: br i1 [[TMP4]], label [[INNERHEADER_PRELOOP]], label [[PRELOOP_EXIT_SELECTOR:%.*]], [[LOOP0:!llvm.loop !.*]], !irce.loop.clone !5
100103
; CHECK: preloop.exit.selector:
101104
; CHECK-NEXT: [[TMP6_PRELOOP_LCSSA:%.*]] = phi i32 [ [[TMP6_PRELOOP]], [[BB8_PRELOOP]] ]
102-
; CHECK-NEXT: [[TMP4:%.*]] = icmp slt i32 [[TMP6_PRELOOP_LCSSA]], 84
103-
; CHECK-NEXT: br i1 [[TMP4]], label [[PRELOOP_PSEUDO_EXIT]], label [[BB13]]
105+
; CHECK-NEXT: [[TMP5:%.*]] = icmp slt i32 [[TMP6_PRELOOP_LCSSA]], 84
106+
; CHECK-NEXT: br i1 [[TMP5]], label [[PRELOOP_PSEUDO_EXIT]], label [[BB13]]
104107
; CHECK: preloop.pseudo.exit:
105108
; CHECK-NEXT: [[TMP4_PRELOOP_COPY]] = phi i32 [ undef, [[BB2]] ], [ [[TMP6_PRELOOP_LCSSA]], [[PRELOOP_EXIT_SELECTOR]] ]
106109
; CHECK-NEXT: [[INDVAR_END]] = phi i32 [ undef, [[BB2]] ], [ [[TMP6_PRELOOP_LCSSA]], [[PRELOOP_EXIT_SELECTOR]] ]
@@ -110,14 +113,14 @@ define void @baz() personality i32* ()* @ham {
110113
; CHECK: innerheader.postloop:
111114
; CHECK-NEXT: [[TMP4_POSTLOOP:%.*]] = phi i32 [ [[TMP6_POSTLOOP:%.*]], [[BB8_POSTLOOP:%.*]] ], [ [[TMP4_COPY]], [[POSTLOOP]] ]
112115
; CHECK-NEXT: invoke void @pluto()
113-
; CHECK-NEXT: to label [[BB5_POSTLOOP:%.*]] unwind label %outer_exiting.loopexit.split-lp.loopexit
116+
; CHECK-NEXT: to label [[BB5_POSTLOOP:%.*]] unwind label [[OUTER_EXITING_LOOPEXIT_SPLIT_LP_LOOPEXIT:%.*]]
114117
; CHECK: bb5.postloop:
115118
; CHECK-NEXT: [[TMP6_POSTLOOP]] = add i32 [[TMP4_POSTLOOP]], 1
116119
; CHECK-NEXT: [[TMP7_POSTLOOP:%.*]] = icmp slt i32 [[TMP6_POSTLOOP]], 1
117120
; CHECK-NEXT: br i1 [[TMP7_POSTLOOP]], label [[BB8_POSTLOOP]], label [[EXIT3_LOOPEXIT4:%.*]]
118121
; CHECK: bb8.postloop:
119122
; CHECK-NEXT: [[TMP9_POSTLOOP:%.*]] = icmp slt i32 [[TMP6_POSTLOOP]], 84
120-
; CHECK-NEXT: br i1 [[TMP9_POSTLOOP]], label [[INNERHEADER_POSTLOOP]], label [[BB13_LOOPEXIT:%.*]], !llvm.loop !6, !irce.loop.clone !5
123+
; CHECK-NEXT: br i1 [[TMP9_POSTLOOP]], label [[INNERHEADER_POSTLOOP]], label [[BB13_LOOPEXIT:%.*]], [[LOOP6:!llvm.loop !.*]], !irce.loop.clone !5
121124
;
122125
bb:
123126
br label %outerheader

llvm/test/Transforms/IRCE/decrementing-loop.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ define void @decrementing_loop(i32 *%arr, i32 *%a_len_ptr, i32 %n) {
2929
ret void
3030

3131
; CHECK: loop.preheader:
32-
; CHECK: [[len_hiclamp_cmp:[^ ]+]] = icmp slt i32 %len, %n
33-
; CHECK: [[len_hiclamp:[^ ]+]] = select i1 [[len_hiclamp_cmp]], i32 %len, i32 %n
34-
; CHECK: [[not_exit_preloop_at_cmp:[^ ]+]] = icmp sgt i32 [[len_hiclamp]], 0
35-
; CHECK: [[not_exit_preloop_at:[^ ]+]] = select i1 [[not_exit_preloop_at_cmp]], i32 [[len_hiclamp]], i32 0
32+
; CHECK: [[len_hiclamp:[^ ]+]] = call i32 @llvm.smin.i32(i32 %len, i32 %n)
33+
; CHECK: [[not_exit_preloop_at:[^ ]+]] = call i32 @llvm.smax.i32(i32 [[len_hiclamp]], i32 0)
3634
; CHECK: %exit.preloop.at = add nsw i32 [[not_exit_preloop_at]], -1
3735
}
3836

llvm/test/Transforms/IRCE/multiple-access-no-preloop.ll

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,9 @@ define void @multiple_access_no_preloop(
3838
; CHECK-LABEL: @multiple_access_no_preloop(
3939

4040
; CHECK: loop.preheader:
41-
; CHECK: [[smax_len_cond:[^ ]+]] = icmp slt i32 %len.b, %len.a
42-
; CHECK: [[smax_len:[^ ]+]] = select i1 [[smax_len_cond]], i32 %len.b, i32 %len.a
43-
; CHECK: [[upper_limit_cond_loclamp:[^ ]+]] = icmp slt i32 [[smax_len]], %n
44-
; CHECK: [[upper_limit_loclamp:[^ ]+]] = select i1 [[upper_limit_cond_loclamp]], i32 [[smax_len]], i32 %n
45-
; CHECK: [[upper_limit_cmp:[^ ]+]] = icmp sgt i32 [[upper_limit_loclamp]], 0
46-
; CHECK: [[upper_limit:[^ ]+]] = select i1 [[upper_limit_cmp]], i32 [[upper_limit_loclamp]], i32 0
41+
; CHECK: [[smax_len:[^ ]+]] = call i32 @llvm.smin.i32(i32 %len.b, i32 %len.a)
42+
; CHECK: [[upper_limit_loclamp:[^ ]+]] = call i32 @llvm.smin.i32(i32 [[smax_len]], i32 %n)
43+
; CHECK: [[upper_limit:[^ ]+]] = call i32 @llvm.smax.i32(i32 [[upper_limit_loclamp]], i32 0)
4744

4845
; CHECK: loop:
4946
; CHECK: br i1 true, label %in.bounds.a, label %out.of.bounds

0 commit comments

Comments
 (0)