1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -verify-loop-info -passes=irce < %s | FileCheck %s
3 ; RUN: opt -S -verify-loop-info -passes='require<branch-prob>,irce' < %s | FileCheck %s
5 define void @f_0(ptr %arr, ptr %a_len_ptr, i32 %n, ptr %cond_buf) {
8 ; CHECK-NEXT: [[LEN:%.*]] = load i32, ptr [[A_LEN_PTR:%.*]], align 4, !range [[RNG0:![0-9]+]]
9 ; CHECK-NEXT: [[FIRST_ITR_CHECK:%.*]] = icmp sgt i32 [[N:%.*]], 0
10 ; CHECK-NEXT: br i1 [[FIRST_ITR_CHECK]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
11 ; CHECK: loop.preheader:
12 ; CHECK-NEXT: [[TMP0:%.*]] = add nsw i32 [[LEN]], -4
13 ; CHECK-NEXT: [[SMIN:%.*]] = call i32 @llvm.smin.i32(i32 [[N]], i32 [[TMP0]])
14 ; CHECK-NEXT: [[EXIT_MAINLOOP_AT:%.*]] = call i32 @llvm.smax.i32(i32 [[SMIN]], i32 0)
15 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 0, [[EXIT_MAINLOOP_AT]]
16 ; CHECK-NEXT: br i1 [[TMP1]], label [[LOOP_PREHEADER1:%.*]], label [[MAIN_PSEUDO_EXIT:%.*]]
17 ; CHECK: loop.preheader1:
18 ; CHECK-NEXT: br label [[LOOP:%.*]]
20 ; CHECK-NEXT: [[IDX:%.*]] = phi i32 [ [[IDX_NEXT:%.*]], [[IN_BOUNDS:%.*]] ], [ 0, [[LOOP_PREHEADER1]] ]
21 ; CHECK-NEXT: [[IDX_NEXT]] = add nsw i32 [[IDX]], 1
22 ; CHECK-NEXT: [[IDX_FOR_ABC:%.*]] = add i32 [[IDX]], 4
23 ; CHECK-NEXT: [[ABC_ACTUAL:%.*]] = icmp slt i32 [[IDX_FOR_ABC]], [[LEN]]
24 ; CHECK-NEXT: [[COND:%.*]] = load volatile i1, ptr [[COND_BUF:%.*]], align 1
25 ; CHECK-NEXT: [[ABC:%.*]] = and i1 [[COND]], true
26 ; CHECK-NEXT: br i1 [[ABC]], label [[IN_BOUNDS]], label [[OUT_OF_BOUNDS_LOOPEXIT2:%.*]], !prof [[PROF1:![0-9]+]]
28 ; CHECK-NEXT: [[ADDR:%.*]] = getelementptr i32, ptr [[ARR:%.*]], i32 [[IDX_FOR_ABC]]
29 ; CHECK-NEXT: store i32 0, ptr [[ADDR]], align 4
30 ; CHECK-NEXT: [[NEXT:%.*]] = icmp slt i32 [[IDX_NEXT]], [[N]]
31 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i32 [[IDX_NEXT]], [[EXIT_MAINLOOP_AT]]
32 ; CHECK-NEXT: br i1 [[TMP2]], label [[LOOP]], label [[MAIN_EXIT_SELECTOR:%.*]]
33 ; CHECK: main.exit.selector:
34 ; CHECK-NEXT: [[IDX_NEXT_LCSSA:%.*]] = phi i32 [ [[IDX_NEXT]], [[IN_BOUNDS]] ]
35 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i32 [[IDX_NEXT_LCSSA]], [[N]]
36 ; CHECK-NEXT: br i1 [[TMP3]], label [[MAIN_PSEUDO_EXIT]], label [[EXIT_LOOPEXIT:%.*]]
37 ; CHECK: main.pseudo.exit:
38 ; CHECK-NEXT: [[IDX_COPY:%.*]] = phi i32 [ 0, [[LOOP_PREHEADER]] ], [ [[IDX_NEXT_LCSSA]], [[MAIN_EXIT_SELECTOR]] ]
39 ; CHECK-NEXT: [[INDVAR_END:%.*]] = phi i32 [ 0, [[LOOP_PREHEADER]] ], [ [[IDX_NEXT_LCSSA]], [[MAIN_EXIT_SELECTOR]] ]
40 ; CHECK-NEXT: br label [[POSTLOOP:%.*]]
41 ; CHECK: out.of.bounds.loopexit:
42 ; CHECK-NEXT: br label [[OUT_OF_BOUNDS:%.*]]
43 ; CHECK: out.of.bounds.loopexit2:
44 ; CHECK-NEXT: br label [[OUT_OF_BOUNDS]]
45 ; CHECK: out.of.bounds:
46 ; CHECK-NEXT: ret void
47 ; CHECK: exit.loopexit.loopexit:
48 ; CHECK-NEXT: br label [[EXIT_LOOPEXIT]]
49 ; CHECK: exit.loopexit:
50 ; CHECK-NEXT: br label [[EXIT]]
52 ; CHECK-NEXT: ret void
54 ; CHECK-NEXT: br label [[LOOP_POSTLOOP:%.*]]
55 ; CHECK: loop.postloop:
56 ; CHECK-NEXT: [[IDX_POSTLOOP:%.*]] = phi i32 [ [[IDX_NEXT_POSTLOOP:%.*]], [[IN_BOUNDS_POSTLOOP:%.*]] ], [ [[IDX_COPY]], [[POSTLOOP]] ]
57 ; CHECK-NEXT: [[IDX_NEXT_POSTLOOP]] = add i32 [[IDX_POSTLOOP]], 1
58 ; CHECK-NEXT: [[IDX_FOR_ABC_POSTLOOP:%.*]] = add i32 [[IDX_POSTLOOP]], 4
59 ; CHECK-NEXT: [[ABC_ACTUAL_POSTLOOP:%.*]] = icmp slt i32 [[IDX_FOR_ABC_POSTLOOP]], [[LEN]]
60 ; CHECK-NEXT: [[COND_POSTLOOP:%.*]] = load volatile i1, ptr [[COND_BUF]], align 1
61 ; CHECK-NEXT: [[ABC_POSTLOOP:%.*]] = and i1 [[COND_POSTLOOP]], [[ABC_ACTUAL_POSTLOOP]]
62 ; CHECK-NEXT: br i1 [[ABC_POSTLOOP]], label [[IN_BOUNDS_POSTLOOP]], label [[OUT_OF_BOUNDS_LOOPEXIT:%.*]], !prof [[PROF1]]
63 ; CHECK: in.bounds.postloop:
64 ; CHECK-NEXT: [[ADDR_POSTLOOP:%.*]] = getelementptr i32, ptr [[ARR]], i32 [[IDX_FOR_ABC_POSTLOOP]]
65 ; CHECK-NEXT: store i32 0, ptr [[ADDR_POSTLOOP]], align 4
66 ; CHECK-NEXT: [[NEXT_POSTLOOP:%.*]] = icmp slt i32 [[IDX_NEXT_POSTLOOP]], [[N]]
67 ; CHECK-NEXT: br i1 [[NEXT_POSTLOOP]], label [[LOOP_POSTLOOP]], label [[EXIT_LOOPEXIT_LOOPEXIT:%.*]], !llvm.loop [[LOOP2:![0-9]+]], !loop_constrainer.loop.clone [[META7:![0-9]+]]
70 %len = load i32, ptr %a_len_ptr, !range !0
71 %first.itr.check = icmp sgt i32 %n, 0
72 br i1 %first.itr.check, label %loop, label %exit
75 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
76 %idx.next = add i32 %idx, 1
77 %idx.for.abc = add i32 %idx, 4
78 %abc.actual = icmp slt i32 %idx.for.abc, %len
79 %cond = load volatile i1, ptr %cond_buf
80 %abc = and i1 %cond, %abc.actual
81 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1
84 %addr = getelementptr i32, ptr %arr, i32 %idx.for.abc
85 store i32 0, ptr %addr
86 %next = icmp slt i32 %idx.next, %n
87 br i1 %next, label %loop, label %exit
99 ; CHECK-NEXT: [[LEN_A:%.*]] = load i32, ptr [[A_LEN_PTR:%.*]], align 4, !range [[RNG0]]
100 ; CHECK-NEXT: [[LEN_B:%.*]] = load i32, ptr [[B_LEN_PTR:%.*]], align 4, !range [[RNG0]]
101 ; CHECK-NEXT: [[FIRST_ITR_CHECK:%.*]] = icmp sgt i32 [[N:%.*]], 0
102 ; CHECK-NEXT: br i1 [[FIRST_ITR_CHECK]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
103 ; CHECK: loop.preheader:
104 ; CHECK-NEXT: [[SMIN:%.*]] = call i32 @llvm.smin.i32(i32 [[LEN_B]], i32 [[LEN_A]])
105 ; CHECK-NEXT: [[SMIN1:%.*]] = call i32 @llvm.smin.i32(i32 [[SMIN]], i32 [[N]])
106 ; CHECK-NEXT: [[EXIT_MAINLOOP_AT:%.*]] = call i32 @llvm.smax.i32(i32 [[SMIN1]], i32 0)
107 ; CHECK-NEXT: [[TMP0:%.*]] = icmp slt i32 0, [[EXIT_MAINLOOP_AT]]
108 ; CHECK-NEXT: br i1 [[TMP0]], label [[LOOP_PREHEADER2:%.*]], label [[MAIN_PSEUDO_EXIT:%.*]]
109 ; CHECK: loop.preheader2:
110 ; CHECK-NEXT: br label [[LOOP:%.*]]
112 ; CHECK-NEXT: [[IDX:%.*]] = phi i32 [ [[IDX_NEXT:%.*]], [[IN_BOUNDS:%.*]] ], [ 0, [[LOOP_PREHEADER2]] ]
113 ; CHECK-NEXT: [[IDX_NEXT]] = add nsw i32 [[IDX]], 1
114 ; CHECK-NEXT: [[ABC_A:%.*]] = icmp slt i32 [[IDX]], [[LEN_A]]
115 ; CHECK-NEXT: [[ABC_B:%.*]] = icmp slt i32 [[IDX]], [[LEN_B]]
116 ; CHECK-NEXT: [[ABC:%.*]] = and i1 true, true
117 ; CHECK-NEXT: br i1 [[ABC]], label [[IN_BOUNDS]], label [[OUT_OF_BOUNDS_LOOPEXIT3:%.*]], !prof [[PROF1]]
119 ; CHECK-NEXT: [[ADDR_A:%.*]] = getelementptr i32, ptr [[ARR_A:%.*]], i32 [[IDX]]
120 ; CHECK-NEXT: store i32 0, ptr [[ADDR_A]], align 4
121 ; CHECK-NEXT: [[ADDR_B:%.*]] = getelementptr i32, ptr [[ARR_B:%.*]], i32 [[IDX]]
122 ; CHECK-NEXT: store i32 -1, ptr [[ADDR_B]], align 4
123 ; CHECK-NEXT: [[NEXT:%.*]] = icmp slt i32 [[IDX_NEXT]], [[N]]
124 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[IDX_NEXT]], [[EXIT_MAINLOOP_AT]]
125 ; CHECK-NEXT: br i1 [[TMP1]], label [[LOOP]], label [[MAIN_EXIT_SELECTOR:%.*]]
126 ; CHECK: main.exit.selector:
127 ; CHECK-NEXT: [[IDX_NEXT_LCSSA:%.*]] = phi i32 [ [[IDX_NEXT]], [[IN_BOUNDS]] ]
128 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i32 [[IDX_NEXT_LCSSA]], [[N]]
129 ; CHECK-NEXT: br i1 [[TMP2]], label [[MAIN_PSEUDO_EXIT]], label [[EXIT_LOOPEXIT:%.*]]
130 ; CHECK: main.pseudo.exit:
131 ; CHECK-NEXT: [[IDX_COPY:%.*]] = phi i32 [ 0, [[LOOP_PREHEADER]] ], [ [[IDX_NEXT_LCSSA]], [[MAIN_EXIT_SELECTOR]] ]
132 ; CHECK-NEXT: [[INDVAR_END:%.*]] = phi i32 [ 0, [[LOOP_PREHEADER]] ], [ [[IDX_NEXT_LCSSA]], [[MAIN_EXIT_SELECTOR]] ]
133 ; CHECK-NEXT: br label [[POSTLOOP:%.*]]
134 ; CHECK: out.of.bounds.loopexit:
135 ; CHECK-NEXT: br label [[OUT_OF_BOUNDS:%.*]]
136 ; CHECK: out.of.bounds.loopexit3:
137 ; CHECK-NEXT: br label [[OUT_OF_BOUNDS]]
138 ; CHECK: out.of.bounds:
139 ; CHECK-NEXT: ret void
140 ; CHECK: exit.loopexit.loopexit:
141 ; CHECK-NEXT: br label [[EXIT_LOOPEXIT]]
142 ; CHECK: exit.loopexit:
143 ; CHECK-NEXT: br label [[EXIT]]
145 ; CHECK-NEXT: ret void
147 ; CHECK-NEXT: br label [[LOOP_POSTLOOP:%.*]]
148 ; CHECK: loop.postloop:
149 ; CHECK-NEXT: [[IDX_POSTLOOP:%.*]] = phi i32 [ [[IDX_NEXT_POSTLOOP:%.*]], [[IN_BOUNDS_POSTLOOP:%.*]] ], [ [[IDX_COPY]], [[POSTLOOP]] ]
150 ; CHECK-NEXT: [[IDX_NEXT_POSTLOOP]] = add i32 [[IDX_POSTLOOP]], 1
151 ; CHECK-NEXT: [[ABC_A_POSTLOOP:%.*]] = icmp slt i32 [[IDX_POSTLOOP]], [[LEN_A]]
152 ; CHECK-NEXT: [[ABC_B_POSTLOOP:%.*]] = icmp slt i32 [[IDX_POSTLOOP]], [[LEN_B]]
153 ; CHECK-NEXT: [[ABC_POSTLOOP:%.*]] = and i1 [[ABC_A_POSTLOOP]], [[ABC_B_POSTLOOP]]
154 ; CHECK-NEXT: br i1 [[ABC_POSTLOOP]], label [[IN_BOUNDS_POSTLOOP]], label [[OUT_OF_BOUNDS_LOOPEXIT:%.*]], !prof [[PROF1]]
155 ; CHECK: in.bounds.postloop:
156 ; CHECK-NEXT: [[ADDR_A_POSTLOOP:%.*]] = getelementptr i32, ptr [[ARR_A]], i32 [[IDX_POSTLOOP]]
157 ; CHECK-NEXT: store i32 0, ptr [[ADDR_A_POSTLOOP]], align 4
158 ; CHECK-NEXT: [[ADDR_B_POSTLOOP:%.*]] = getelementptr i32, ptr [[ARR_B]], i32 [[IDX_POSTLOOP]]
159 ; CHECK-NEXT: store i32 -1, ptr [[ADDR_B_POSTLOOP]], align 4
160 ; CHECK-NEXT: [[NEXT_POSTLOOP:%.*]] = icmp slt i32 [[IDX_NEXT_POSTLOOP]], [[N]]
161 ; CHECK-NEXT: br i1 [[NEXT_POSTLOOP]], label [[LOOP_POSTLOOP]], label [[EXIT_LOOPEXIT_LOOPEXIT:%.*]], !llvm.loop [[LOOP8:![0-9]+]], !loop_constrainer.loop.clone [[META7]]
163 ptr %arr_a, ptr %a_len_ptr, ptr %arr_b, ptr %b_len_ptr, i32 %n) {
167 %len.a = load i32, ptr %a_len_ptr, !range !0
168 %len.b = load i32, ptr %b_len_ptr, !range !0
169 %first.itr.check = icmp sgt i32 %n, 0
170 br i1 %first.itr.check, label %loop, label %exit
173 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
174 %idx.next = add i32 %idx, 1
175 %abc.a = icmp slt i32 %idx, %len.a
176 %abc.b = icmp slt i32 %idx, %len.b
177 %abc = and i1 %abc.a, %abc.b
178 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1
181 %addr.a = getelementptr i32, ptr %arr_a, i32 %idx
182 store i32 0, ptr %addr.a
183 %addr.b = getelementptr i32, ptr %arr_b, i32 %idx
184 store i32 -1, ptr %addr.b
185 %next = icmp slt i32 %idx.next, %n
186 br i1 %next, label %loop, label %exit
195 !0 = !{i32 0, i32 2147483647}
196 !1 = !{!"branch_weights", i32 64, i32 4}