1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
2 ; RUN: opt -S -passes='simple-loop-unswitch<nontrivial>' < %s | FileCheck %s
4 ; Make sure invariant condition injection does not result in exponential
7 ; FIXME: It probably shouldn't result in linear size increase either.
9 define void @ham(i64 %arg) {
10 ; CHECK-LABEL: define void @ham(
11 ; CHECK-SAME: i64 [[ARG:%.*]]) {
13 ; CHECK-NEXT: [[INJECTED_COND:%.*]] = icmp ule i64 [[ARG]], [[ARG]]
14 ; CHECK-NEXT: [[INJECTED_COND_FR:%.*]] = freeze i1 [[INJECTED_COND]]
15 ; CHECK-NEXT: br i1 [[INJECTED_COND_FR]], label [[BB_SPLIT_US:%.*]], label [[BB_SPLIT:%.*]]
17 ; CHECK-NEXT: [[INJECTED_COND1:%.*]] = icmp ule i64 [[ARG]], [[ARG]]
18 ; CHECK-NEXT: [[INJECTED_COND1_FR:%.*]] = freeze i1 [[INJECTED_COND1]]
19 ; CHECK-NEXT: br i1 [[INJECTED_COND1_FR]], label [[BB_SPLIT_US_SPLIT_US:%.*]], label [[BB_SPLIT_US_SPLIT:%.*]]
20 ; CHECK: bb.split.us.split.us:
21 ; CHECK-NEXT: [[INJECTED_COND2:%.*]] = icmp ule i64 [[ARG]], [[ARG]]
22 ; CHECK-NEXT: [[INJECTED_COND2_FR:%.*]] = freeze i1 [[INJECTED_COND2]]
23 ; CHECK-NEXT: br i1 [[INJECTED_COND2_FR]], label [[BB_SPLIT_US_SPLIT_US_SPLIT_US:%.*]], label [[BB_SPLIT_US_SPLIT_US_SPLIT:%.*]]
24 ; CHECK: bb.split.us.split.us.split.us:
25 ; CHECK-NEXT: [[INJECTED_COND3:%.*]] = icmp ule i64 [[ARG]], [[ARG]]
26 ; CHECK-NEXT: [[INJECTED_COND3_FR:%.*]] = freeze i1 [[INJECTED_COND3]]
27 ; CHECK-NEXT: br i1 [[INJECTED_COND3_FR]], label [[BB_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT_US:%.*]], label [[BB_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT:%.*]]
28 ; CHECK: bb.split.us.split.us.split.us.split.us:
29 ; CHECK-NEXT: [[INJECTED_COND4:%.*]] = icmp ule i64 [[ARG]], [[ARG]]
30 ; CHECK-NEXT: [[INJECTED_COND4_FR:%.*]] = freeze i1 [[INJECTED_COND4]]
31 ; CHECK-NEXT: br i1 [[INJECTED_COND4_FR]], label [[BB_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT_US:%.*]], label [[BB_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT:%.*]]
32 ; CHECK: bb.split.us.split.us.split.us.split.us.split.us:
33 ; CHECK-NEXT: br label [[BB1_US_US_US_US_US:%.*]]
34 ; CHECK: bb1.us.us.us.us.us:
35 ; CHECK-NEXT: [[PHI_US_US_US_US_US:%.*]] = phi i64 [ 0, [[BB_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT_US]] ], [ [[ADD_US_US_US_US_US:%.*]], [[BB20_US_US_US_US_US:%.*]] ]
36 ; CHECK-NEXT: [[ADD_US_US_US_US_US]] = add nuw i64 [[PHI_US_US_US_US_US]], 1
37 ; CHECK-NEXT: [[ICMP_US_US_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US_US_US]], [[ARG]]
38 ; CHECK-NEXT: br i1 [[ICMP_US_US_US_US_US]], label [[BB2_US_US_US_US_US:%.*]], label [[BB21_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT_US:%.*]], !prof [[PROF0:![0-9]+]]
39 ; CHECK: bb2.us.us.us.us.us:
40 ; CHECK-NEXT: [[ICMP3_US_US_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US_US_US]], [[ARG]]
41 ; CHECK-NEXT: br label [[BB4_US_US_US_US_US:%.*]]
42 ; CHECK: bb4.us.us.us.us.us:
43 ; CHECK-NEXT: [[ICMP5_US_US_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US_US_US]], [[ARG]]
44 ; CHECK-NEXT: br label [[BB6_US_US_US_US_US:%.*]]
45 ; CHECK: bb6.us.us.us.us.us:
46 ; CHECK-NEXT: [[ICMP7_US_US_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US_US_US]], [[ARG]]
47 ; CHECK-NEXT: br label [[BB8_US_US_US_US_US:%.*]]
48 ; CHECK: bb8.us.us.us.us.us:
49 ; CHECK-NEXT: [[ICMP9_US_US_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US_US_US]], [[ARG]]
50 ; CHECK-NEXT: br label [[BB10_US_US_US_US_US:%.*]]
51 ; CHECK: bb10.us.us.us.us.us:
52 ; CHECK-NEXT: [[ICMP11_US_US_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US_US_US]], [[ARG]]
53 ; CHECK-NEXT: br label [[BB20_US_US_US_US_US]]
54 ; CHECK: bb20.us.us.us.us.us:
55 ; CHECK-NEXT: br label [[BB1_US_US_US_US_US]]
56 ; CHECK: bb21.split.us.split.us.split.us.split.us.split.us:
57 ; CHECK-NEXT: br label [[BB21_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT_US:%.*]]
58 ; CHECK: bb.split.us.split.us.split.us.split.us.split:
59 ; CHECK-NEXT: br label [[BB1_US_US_US_US:%.*]]
60 ; CHECK: bb1.us.us.us.us:
61 ; CHECK-NEXT: [[PHI_US_US_US_US:%.*]] = phi i64 [ 0, [[BB_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT]] ], [ [[ADD_US_US_US_US:%.*]], [[BB20_US_US_US_US:%.*]] ]
62 ; CHECK-NEXT: [[ADD_US_US_US_US]] = add nuw i64 [[PHI_US_US_US_US]], 1
63 ; CHECK-NEXT: [[ICMP_US_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US_US]], [[ARG]]
64 ; CHECK-NEXT: br i1 [[ICMP_US_US_US_US]], label [[BB2_US_US_US_US:%.*]], label [[BB21_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT:%.*]], !prof [[PROF0]]
65 ; CHECK: bb2.us.us.us.us:
66 ; CHECK-NEXT: [[ICMP3_US_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US_US]], [[ARG]]
67 ; CHECK-NEXT: br label [[BB4_US_US_US_US:%.*]]
68 ; CHECK: bb4.us.us.us.us:
69 ; CHECK-NEXT: [[ICMP5_US_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US_US]], [[ARG]]
70 ; CHECK-NEXT: br label [[BB6_US_US_US_US:%.*]]
71 ; CHECK: bb6.us.us.us.us:
72 ; CHECK-NEXT: [[ICMP7_US_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US_US]], [[ARG]]
73 ; CHECK-NEXT: br label [[BB8_US_US_US_US:%.*]]
74 ; CHECK: bb8.us.us.us.us:
75 ; CHECK-NEXT: [[ICMP9_US_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US_US]], [[ARG]]
76 ; CHECK-NEXT: br label [[BB10_US_US_US_US:%.*]]
77 ; CHECK: bb10.us.us.us.us:
78 ; CHECK-NEXT: [[ICMP11_US_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US_US]], [[ARG]]
79 ; CHECK-NEXT: br label [[BB10_US_US_US_US_CHECK:%.*]]
80 ; CHECK: bb10.us.us.us.us.check:
81 ; CHECK-NEXT: br i1 [[ICMP11_US_US_US_US]], label [[BB20_US_US_US_US]], label [[BB21_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT]]
82 ; CHECK: bb20.us.us.us.us:
83 ; CHECK-NEXT: br label [[BB1_US_US_US_US]], !llvm.loop [[LOOP1:![0-9]+]]
84 ; CHECK: bb21.split.us.split.us.split.us.split.us.split:
85 ; CHECK-NEXT: br label [[BB21_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT_US]]
86 ; CHECK: bb21.split.us.split.us.split.us.split.us:
87 ; CHECK-NEXT: br label [[BB21_SPLIT_US_SPLIT_US_SPLIT_US:%.*]]
88 ; CHECK: bb.split.us.split.us.split.us.split:
89 ; CHECK-NEXT: br label [[BB1_US_US_US:%.*]]
90 ; CHECK: bb1.us.us.us:
91 ; CHECK-NEXT: [[PHI_US_US_US:%.*]] = phi i64 [ 0, [[BB_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT]] ], [ [[ADD_US_US_US:%.*]], [[BB20_US_US_US:%.*]] ]
92 ; CHECK-NEXT: [[ADD_US_US_US]] = add nuw i64 [[PHI_US_US_US]], 1
93 ; CHECK-NEXT: [[ICMP_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US]], [[ARG]]
94 ; CHECK-NEXT: br i1 [[ICMP_US_US_US]], label [[BB2_US_US_US:%.*]], label [[BB21_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT:%.*]], !prof [[PROF0]]
95 ; CHECK: bb2.us.us.us:
96 ; CHECK-NEXT: [[ICMP3_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US]], [[ARG]]
97 ; CHECK-NEXT: br label [[BB4_US_US_US:%.*]]
98 ; CHECK: bb4.us.us.us:
99 ; CHECK-NEXT: [[ICMP5_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US]], [[ARG]]
100 ; CHECK-NEXT: br label [[BB6_US_US_US:%.*]]
101 ; CHECK: bb6.us.us.us:
102 ; CHECK-NEXT: [[ICMP7_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US]], [[ARG]]
103 ; CHECK-NEXT: br label [[BB8_US_US_US:%.*]]
104 ; CHECK: bb8.us.us.us:
105 ; CHECK-NEXT: [[ICMP9_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US]], [[ARG]]
106 ; CHECK-NEXT: br label [[BB8_US_US_US_CHECK:%.*]]
107 ; CHECK: bb8.us.us.us.check:
108 ; CHECK-NEXT: br i1 [[ICMP9_US_US_US]], label [[BB10_US_US_US:%.*]], label [[BB21_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT]]
109 ; CHECK: bb10.us.us.us:
110 ; CHECK-NEXT: [[ICMP11_US_US_US:%.*]] = icmp ult i64 [[PHI_US_US_US]], [[ARG]]
111 ; CHECK-NEXT: br i1 [[ICMP11_US_US_US]], label [[BB20_US_US_US]], label [[BB21_SPLIT_US_SPLIT_US_SPLIT_US_SPLIT]], !prof [[PROF0]]
112 ; CHECK: bb20.us.us.us:
113 ; CHECK-NEXT: br label [[BB1_US_US_US]], !llvm.loop [[LOOP3:![0-9]+]]
114 ; CHECK: bb21.split.us.split.us.split.us.split:
115 ; CHECK-NEXT: br label [[BB21_SPLIT_US_SPLIT_US_SPLIT_US]]
116 ; CHECK: bb21.split.us.split.us.split.us:
117 ; CHECK-NEXT: br label [[BB21_SPLIT_US_SPLIT_US:%.*]]
118 ; CHECK: bb.split.us.split.us.split:
119 ; CHECK-NEXT: br label [[BB1_US_US:%.*]]
121 ; CHECK-NEXT: [[PHI_US_US:%.*]] = phi i64 [ 0, [[BB_SPLIT_US_SPLIT_US_SPLIT]] ], [ [[ADD_US_US:%.*]], [[BB20_US_US:%.*]] ]
122 ; CHECK-NEXT: [[ADD_US_US]] = add nuw i64 [[PHI_US_US]], 1
123 ; CHECK-NEXT: [[ICMP_US_US:%.*]] = icmp ult i64 [[PHI_US_US]], [[ARG]]
124 ; CHECK-NEXT: br i1 [[ICMP_US_US]], label [[BB2_US_US:%.*]], label [[BB21_SPLIT_US_SPLIT_US_SPLIT:%.*]], !prof [[PROF0]]
126 ; CHECK-NEXT: [[ICMP3_US_US:%.*]] = icmp ult i64 [[PHI_US_US]], [[ARG]]
127 ; CHECK-NEXT: br label [[BB4_US_US:%.*]]
129 ; CHECK-NEXT: [[ICMP5_US_US:%.*]] = icmp ult i64 [[PHI_US_US]], [[ARG]]
130 ; CHECK-NEXT: br label [[BB6_US_US:%.*]]
132 ; CHECK-NEXT: [[ICMP7_US_US:%.*]] = icmp ult i64 [[PHI_US_US]], [[ARG]]
133 ; CHECK-NEXT: br label [[BB6_US_US_CHECK:%.*]]
134 ; CHECK: bb6.us.us.check:
135 ; CHECK-NEXT: br i1 [[ICMP7_US_US]], label [[BB8_US_US:%.*]], label [[BB21_SPLIT_US_SPLIT_US_SPLIT]]
137 ; CHECK-NEXT: [[ICMP9_US_US:%.*]] = icmp ult i64 [[PHI_US_US]], [[ARG]]
138 ; CHECK-NEXT: br i1 [[ICMP9_US_US]], label [[BB10_US_US:%.*]], label [[BB21_SPLIT_US_SPLIT_US_SPLIT]], !prof [[PROF0]]
140 ; CHECK-NEXT: [[ICMP11_US_US:%.*]] = icmp ult i64 [[PHI_US_US]], [[ARG]]
141 ; CHECK-NEXT: br i1 [[ICMP11_US_US]], label [[BB20_US_US]], label [[BB21_SPLIT_US_SPLIT_US_SPLIT]], !prof [[PROF0]]
143 ; CHECK-NEXT: br label [[BB1_US_US]], !llvm.loop [[LOOP4:![0-9]+]]
144 ; CHECK: bb21.split.us.split.us.split:
145 ; CHECK-NEXT: br label [[BB21_SPLIT_US_SPLIT_US]]
146 ; CHECK: bb21.split.us.split.us:
147 ; CHECK-NEXT: br label [[BB21_SPLIT_US:%.*]]
148 ; CHECK: bb.split.us.split:
149 ; CHECK-NEXT: br label [[BB1_US:%.*]]
151 ; CHECK-NEXT: [[PHI_US:%.*]] = phi i64 [ 0, [[BB_SPLIT_US_SPLIT]] ], [ [[ADD_US:%.*]], [[BB20_US:%.*]] ]
152 ; CHECK-NEXT: [[ADD_US]] = add nuw i64 [[PHI_US]], 1
153 ; CHECK-NEXT: [[ICMP_US:%.*]] = icmp ult i64 [[PHI_US]], [[ARG]]
154 ; CHECK-NEXT: br i1 [[ICMP_US]], label [[BB2_US:%.*]], label [[BB21_SPLIT_US_SPLIT:%.*]], !prof [[PROF0]]
156 ; CHECK-NEXT: [[ICMP3_US:%.*]] = icmp ult i64 [[PHI_US]], [[ARG]]
157 ; CHECK-NEXT: br label [[BB4_US:%.*]]
159 ; CHECK-NEXT: [[ICMP5_US:%.*]] = icmp ult i64 [[PHI_US]], [[ARG]]
160 ; CHECK-NEXT: br label [[BB4_US_CHECK:%.*]]
161 ; CHECK: bb4.us.check:
162 ; CHECK-NEXT: br i1 [[ICMP5_US]], label [[BB6_US:%.*]], label [[BB22_SPLIT_US:%.*]]
164 ; CHECK-NEXT: [[ICMP7_US:%.*]] = icmp ult i64 [[PHI_US]], [[ARG]]
165 ; CHECK-NEXT: br i1 [[ICMP7_US]], label [[BB8_US:%.*]], label [[BB21_SPLIT_US_SPLIT]], !prof [[PROF0]]
167 ; CHECK-NEXT: [[ICMP9_US:%.*]] = icmp ult i64 [[PHI_US]], [[ARG]]
168 ; CHECK-NEXT: br i1 [[ICMP9_US]], label [[BB10_US:%.*]], label [[BB21_SPLIT_US_SPLIT]], !prof [[PROF0]]
170 ; CHECK-NEXT: [[ICMP11_US:%.*]] = icmp ult i64 [[PHI_US]], [[ARG]]
171 ; CHECK-NEXT: br i1 [[ICMP11_US]], label [[BB20_US]], label [[BB21_SPLIT_US_SPLIT]], !prof [[PROF0]]
173 ; CHECK-NEXT: br label [[BB1_US]], !llvm.loop [[LOOP5:![0-9]+]]
174 ; CHECK: bb21.split.us.split:
175 ; CHECK-NEXT: br label [[BB21_SPLIT_US]]
176 ; CHECK: bb21.split.us:
177 ; CHECK-NEXT: br label [[BB21:%.*]]
178 ; CHECK: bb22.split.us:
179 ; CHECK-NEXT: br label [[BB22:%.*]]
181 ; CHECK-NEXT: br label [[BB1:%.*]]
183 ; CHECK-NEXT: [[PHI:%.*]] = phi i64 [ 0, [[BB_SPLIT]] ], [ [[ADD:%.*]], [[BB20:%.*]] ]
184 ; CHECK-NEXT: [[ADD]] = add nuw i64 [[PHI]], 1
185 ; CHECK-NEXT: [[ICMP:%.*]] = icmp ult i64 [[PHI]], [[ARG]]
186 ; CHECK-NEXT: br i1 [[ICMP]], label [[BB2:%.*]], label [[BB21_SPLIT:%.*]], !prof [[PROF0]]
188 ; CHECK-NEXT: [[ICMP3:%.*]] = icmp ult i64 [[PHI]], [[ARG]]
189 ; CHECK-NEXT: br label [[BB2_CHECK:%.*]]
191 ; CHECK-NEXT: br i1 [[ICMP3]], label [[BB4:%.*]], label [[BB21_SPLIT]]
193 ; CHECK-NEXT: [[ICMP5:%.*]] = icmp ult i64 [[PHI]], [[ARG]]
194 ; CHECK-NEXT: br i1 [[ICMP5]], label [[BB6:%.*]], label [[BB22_SPLIT:%.*]], !prof [[PROF0]]
196 ; CHECK-NEXT: [[ICMP7:%.*]] = icmp ult i64 [[PHI]], [[ARG]]
197 ; CHECK-NEXT: br i1 [[ICMP7]], label [[BB8:%.*]], label [[BB21_SPLIT]], !prof [[PROF0]]
199 ; CHECK-NEXT: [[ICMP9:%.*]] = icmp ult i64 [[PHI]], [[ARG]]
200 ; CHECK-NEXT: br i1 [[ICMP9]], label [[BB10:%.*]], label [[BB21_SPLIT]], !prof [[PROF0]]
202 ; CHECK-NEXT: [[ICMP11:%.*]] = icmp ult i64 [[PHI]], [[ARG]]
203 ; CHECK-NEXT: br i1 [[ICMP11]], label [[BB20]], label [[BB21_SPLIT]], !prof [[PROF0]]
205 ; CHECK-NEXT: br label [[BB1]], !llvm.loop [[LOOP6:![0-9]+]]
207 ; CHECK-NEXT: br label [[BB21]]
209 ; CHECK-NEXT: call void @zot()
210 ; CHECK-NEXT: ret void
212 ; CHECK-NEXT: br label [[BB22]]
214 ; CHECK-NEXT: call void @zot()
215 ; CHECK-NEXT: ret void
220 bb1: ; preds = %bb20, %bb
221 %phi = phi i64 [ 0, %bb ], [ %add, %bb20 ]
222 %add = add nuw i64 %phi, 1
223 %icmp = icmp ult i64 %phi, %arg
224 br i1 %icmp, label %bb2, label %bb21, !prof !0
227 %icmp3 = icmp ult i64 %phi, %arg
228 br i1 %icmp3, label %bb4, label %bb21, !prof !0
231 %icmp5 = icmp ult i64 %phi, %arg
232 br i1 %icmp5, label %bb6, label %bb22, !prof !0
235 %icmp7 = icmp ult i64 %phi, %arg
236 br i1 %icmp7, label %bb8, label %bb21, !prof !0
239 %icmp9 = icmp ult i64 %phi, %arg
240 br i1 %icmp9, label %bb10, label %bb21, !prof !0
243 %icmp11 = icmp ult i64 %phi, %arg
244 br i1 %icmp11, label %bb20, label %bb21, !prof !0
246 bb20: ; preds = %bb18
249 bb21: ; preds = %bb18, %bb16, %bb14, %bb12, %bb10, %bb8, %bb6, %bb2, %bb1
260 !0 = !{!"branch_weights", i32 2000, i32 1}