@@ -24,12 +24,189 @@ exit:
24
24
ret void
25
25
}
26
26
27
+ define void @test_guard_less_than_16_branches_flipped (i32* nocapture %a , i64 %i ) {
28
+ ; CHECK-LABEL: Determining loop execution counts for: @test_guard_less_than_16_branches_flipped
29
+ ; CHECK-NEXT: Loop %loop: backedge-taken count is (15 + (-1 * %i))
30
+ ; CHECK-NEXT: Loop %loop: max backedge-taken count is -1
31
+ ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (15 + (-1 * %i))
32
+ ;
33
+ entry:
34
+ %cmp3 = icmp ult i64 %i , 16
35
+ br i1 %cmp3 , label %exit , label %loop
36
+
37
+ loop:
38
+ %iv = phi i64 [ %iv.next , %loop ], [ %i , %entry ]
39
+ %idx = getelementptr inbounds i32 , i32* %a , i64 %iv
40
+ store i32 1 , i32* %idx , align 4
41
+ %iv.next = add nuw nsw i64 %iv , 1
42
+ %exitcond = icmp eq i64 %iv.next , 16
43
+ br i1 %exitcond , label %exit , label %loop
44
+
45
+ exit:
46
+ ret void
47
+ }
48
+
49
+ define void @test_guard_uge_16_branches_flipped (i32* nocapture %a , i64 %i ) {
50
+ ; CHECK-LABEL: Determining loop execution counts for: @test_guard_uge_16_branches_flipped
51
+ ; CHECK-NEXT: Loop %loop: backedge-taken count is (15 + (-1 * %i))
52
+ ; CHECK-NEXT: Loop %loop: max backedge-taken count is -1
53
+ ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (15 + (-1 * %i))
54
+ ;
55
+ entry:
56
+ %cmp3 = icmp uge i64 %i , 16
57
+ br i1 %cmp3 , label %exit , label %loop
58
+
59
+ loop:
60
+ %iv = phi i64 [ %iv.next , %loop ], [ %i , %entry ]
61
+ %idx = getelementptr inbounds i32 , i32* %a , i64 %iv
62
+ store i32 1 , i32* %idx , align 4
63
+ %iv.next = add nuw nsw i64 %iv , 1
64
+ %exitcond = icmp eq i64 %iv.next , 16
65
+ br i1 %exitcond , label %exit , label %loop
66
+
67
+ exit:
68
+ ret void
69
+ }
70
+
71
+ define void @test_multiple_const_guards_order1 (i32* nocapture %a , i64 %i ) {
72
+ ; CHECK-LABEL: @test_multiple_const_guards_order1
73
+ ; CHECK: Loop %loop: backedge-taken count is %i
74
+ ; CHECK-NEXT: Loop %loop: max backedge-taken count is -1
75
+ ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is %i
76
+ ;
77
+ entry:
78
+ %c.1 = icmp ult i64 %i , 16
79
+ br i1 %c.1 , label %guardbb , label %exit
80
+
81
+ guardbb:
82
+ %c.2 = icmp ult i64 %i , 10
83
+ br i1 %c.2 , label %loop , label %exit
84
+
85
+ loop:
86
+ %iv = phi i64 [ %iv.next , %loop ], [ 0 , %guardbb ]
87
+ %idx = getelementptr inbounds i32 , i32* %a , i64 %iv
88
+ store i32 1 , i32* %idx , align 4
89
+ %iv.next = add nuw nsw i64 %iv , 1
90
+ %exitcond = icmp eq i64 %iv , %i
91
+ br i1 %exitcond , label %exit , label %loop
92
+
93
+ exit:
94
+ ret void
95
+ }
96
+
97
+ define void @test_multiple_const_guards_order2 (i32* nocapture %a , i64 %i ) {
98
+ ; CHECK-LABEL: @test_multiple_const_guards_order2
99
+ ; CHECK: Loop %loop: backedge-taken count is %i
100
+ ; CHECK-NEXT: Loop %loop: max backedge-taken count is -1
101
+ ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is %i
102
+ ;
103
+ entry:
104
+ %c.1 = icmp ult i64 %i , 10
105
+ br i1 %c.1 , label %guardbb , label %exit
106
+
107
+ guardbb:
108
+ %c.2 = icmp ult i64 %i , 16
109
+ br i1 %c.2 , label %loop , label %exit
110
+
111
+ loop:
112
+ %iv = phi i64 [ %iv.next , %loop ], [ 0 , %guardbb ]
113
+ %idx = getelementptr inbounds i32 , i32* %a , i64 %iv
114
+ store i32 1 , i32* %idx , align 4
115
+ %iv.next = add nuw nsw i64 %iv , 1
116
+ %exitcond = icmp eq i64 %iv , %i
117
+ br i1 %exitcond , label %exit , label %loop
118
+
119
+ exit:
120
+ ret void
121
+ }
122
+
123
+ ; TODO: Currently we miss getting the tightest max backedge-taken count (11).
124
+ define void @test_multiple_var_guards_order1 (i32* nocapture %a , i64 %i , i64 %N ) {
125
+ ; CHECK-LABEL: @test_multiple_var_guards_order1
126
+ ; CHECK: Loop %loop: backedge-taken count is %i
127
+ ; CHECK-NEXT: Loop %loop: max backedge-taken count is -1
128
+ ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is %i
129
+ ;
130
+ entry:
131
+ %c.1 = icmp ult i64 %N , 12
132
+ br i1 %c.1 , label %guardbb , label %exit
133
+
134
+ guardbb:
135
+ %c.2 = icmp ult i64 %i , %N
136
+ br i1 %c.2 , label %loop , label %exit
137
+
138
+ loop:
139
+ %iv = phi i64 [ %iv.next , %loop ], [ 0 , %guardbb ]
140
+ %idx = getelementptr inbounds i32 , i32* %a , i64 %iv
141
+ store i32 1 , i32* %idx , align 4
142
+ %iv.next = add nuw nsw i64 %iv , 1
143
+ %exitcond = icmp eq i64 %iv , %i
144
+ br i1 %exitcond , label %exit , label %loop
145
+
146
+ exit:
147
+ ret void
148
+ }
149
+
150
+ ; TODO: Currently we miss getting the tightest max backedge-taken count (11).
151
+ define void @test_multiple_var_guards_order2 (i32* nocapture %a , i64 %i , i64 %N ) {
152
+ ; CHECK-LABEL: Determining loop execution counts for: @test_multiple_var_guards_order2
153
+ ; CHECK-NEXT: Loop %loop: backedge-taken count is %i
154
+ ; CHECK-NEXT: Loop %loop: max backedge-taken count is -1
155
+ ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is %i
156
+ ;
157
+ entry:
158
+ %c.1 = icmp ult i64 %i , %N
159
+ br i1 %c.1 , label %guardbb , label %exit
160
+
161
+ guardbb:
162
+ %c.2 = icmp ult i64 %N , 12
163
+ br i1 %c.2 , label %loop , label %exit
164
+
165
+ loop:
166
+ %iv = phi i64 [ %iv.next , %loop ], [ 0 , %guardbb ]
167
+ %idx = getelementptr inbounds i32 , i32* %a , i64 %iv
168
+ store i32 1 , i32* %idx , align 4
169
+ %iv.next = add nuw nsw i64 %iv , 1
170
+ %exitcond = icmp eq i64 %iv , %i
171
+ br i1 %exitcond , label %exit , label %loop
172
+
173
+ exit:
174
+ ret void
175
+ }
176
+
177
+ ; The guards here reference each other in a cycle.
178
+ define void @test_multiple_var_guards_cycle (i32* nocapture %a , i64 %i , i64 %N ) {
179
+ ; CHECK-LABEL: Determining loop execution counts for: @test_multiple_var_guards_cycle
180
+ ; CHECK-NEXT: Loop %loop: backedge-taken count is %N
181
+ ; CHECK-NEXT: Loop %loop: max backedge-taken count is -1
182
+ ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is %N
183
+ ;
184
+ entry:
185
+ %c.1 = icmp ult i64 %N , %i
186
+ br i1 %c.1 , label %guardbb , label %exit
187
+
188
+ guardbb:
189
+ %c.2 = icmp ult i64 %i , %N
190
+ br i1 %c.2 , label %loop , label %exit
191
+
192
+ loop:
193
+ %iv = phi i64 [ %iv.next , %loop ], [ 0 , %guardbb ]
194
+ %idx = getelementptr inbounds i32 , i32* %a , i64 %iv
195
+ store i32 1 , i32* %idx , align 4
196
+ %iv.next = add nuw nsw i64 %iv , 1
197
+ %exitcond = icmp eq i64 %iv , %N
198
+ br i1 %exitcond , label %exit , label %loop
199
+
200
+ exit:
201
+ ret void
202
+ }
203
+
27
204
; Test case for PR47247. Both the guard condition and the assume limit the
28
205
; max backedge-taken count.
29
206
30
207
define void @test_guard_and_assume (i32* nocapture readonly %data , i64 %count ) {
31
- ; CHECK-LABEL: Determining loop execution counts for: @test_guard_and_assume
32
- ; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + %count)
208
+ ; CHECK-LABEL: @test_guard_and_assume
209
+ ; CHECK: Loop %loop: backedge-taken count is (-1 + %count)
33
210
; CHECK-NEXT: Loop %loop: max backedge-taken count is -2
34
211
; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + %count)
35
212
;
@@ -53,3 +230,68 @@ exit:
53
230
54
231
; Function Attrs: nounwind willreturn
55
232
declare void @llvm.assume (i1 noundef)
233
+
234
+ define void @guard_pessimizes_analysis (i1 %c , i32 %N ) {
235
+ ; CHECK-LABEL: @guard_pessimizes_analysis
236
+ ; CHECK: Loop %loop: backedge-taken count is (9 + (-1 * %init)<nsw>)<nsw>
237
+ ; CHECK-NEXT: Loop %loop: max backedge-taken count is 7
238
+ ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (9 + (-1 * %init)<nsw>)<nsw>
239
+ ;
240
+ entry:
241
+ br i1 %c , label %bb1 , label %guard
242
+
243
+ bb1:
244
+ br label %guard
245
+
246
+ guard:
247
+ %init = phi i32 [ 2 , %entry ], [ 3 , %bb1 ]
248
+ %c.1 = icmp ult i32 %init , %N
249
+ br i1 %c.1 , label %loop.ph , label %exit
250
+
251
+ loop.ph:
252
+ br label %loop
253
+
254
+ loop:
255
+ %iv = phi i32 [ %iv.next , %loop ], [ %init , %loop.ph ]
256
+ %iv.next = add i32 %iv , 1
257
+ %exitcond = icmp eq i32 %iv.next , 10
258
+ br i1 %exitcond , label %exit , label %loop
259
+
260
+ exit:
261
+ ret void
262
+ }
263
+
264
+ define void @crash (i8* %ptr ) {
265
+ ; CHECK-LABEL: @crash
266
+ ; CHECK: Loop %while.body125: backedge-taken count is {(-2 + (-1 * %ptr)),+,-1}<nw><%while.cond111>
267
+ ; CHECK-NEXT: Loop %while.body125: max backedge-taken count is -1
268
+ ; CHECK-NEXT: Loop %while.body125: Predicated backedge-taken count is {(-2 + (-1 * %ptr)),+,-1}<nw><%while.cond111>
269
+ ;
270
+ entry:
271
+ br label %while.body
272
+
273
+ while.body:
274
+ br label %while.cond111
275
+
276
+ while.cond111:
277
+ %text.addr.5 = phi i8* [ %incdec.ptr112 , %while.cond111 ], [ null , %while.body ]
278
+ %incdec.ptr112 = getelementptr inbounds i8 , i8* %text.addr.5 , i64 -1
279
+ br i1 false , label %while.end117 , label %while.cond111
280
+
281
+ while.end117:
282
+ %cmp118 = icmp ult i8* %ptr , %incdec.ptr112
283
+ br i1 %cmp118 , label %while.body125 , label %while.cond134.preheader
284
+
285
+
286
+ while.cond134.preheader:
287
+ br label %while.body
288
+
289
+ while.body125:
290
+ %lastout.2271 = phi i8* [ %incdec.ptr126 , %while.body125 ], [ %ptr , %while.end117 ]
291
+ %incdec.ptr126 = getelementptr inbounds i8 , i8* %lastout.2271 , i64 1
292
+ %exitcond.not = icmp eq i8* %incdec.ptr126 , %incdec.ptr112
293
+ br i1 %exitcond.not , label %while.end129 , label %while.body125
294
+
295
+ while.end129: ; preds = %while.body125
296
+ ret void
297
+ }
0 commit comments