1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
| ; RUN: opt < %s -correlated-propagation -cvp-dont-add-nowrap-flags=false -S | FileCheck %s
; CHECK-LABEL: @test0(
define void @test0(i32 %a) {
entry:
%cmp = icmp slt i32 %a, 100
br i1 %cmp, label %bb, label %exit
bb:
; CHECK: %add = add nsw i32 %a, 1
%add = add i32 %a, 1
br label %exit
exit:
ret void
}
; CHECK-LABEL: @test1(
define void @test1(i32 %a) {
entry:
%cmp = icmp ult i32 %a, 100
br i1 %cmp, label %bb, label %exit
bb:
; CHECK: %add = add nuw nsw i32 %a, 1
%add = add i32 %a, 1
br label %exit
exit:
ret void
}
; CHECK-LABEL: @test2(
define void @test2(i32 %a) {
entry:
%cmp = icmp ult i32 %a, -1
br i1 %cmp, label %bb, label %exit
bb:
; CHECK: %add = add nuw i32 %a, 1
%add = add i32 %a, 1
br label %exit
exit:
ret void
}
; CHECK-LABEL: @test3(
define void @test3(i32 %a) {
entry:
%cmp = icmp ule i32 %a, -1
br i1 %cmp, label %bb, label %exit
bb:
; CHECK: %add = add i32 %a, 1
%add = add i32 %a, 1
br label %exit
exit:
ret void
}
; CHECK-LABEL: @test4(
define void @test4(i32 %a) {
entry:
%cmp = icmp slt i32 %a, 2147483647
br i1 %cmp, label %bb, label %exit
bb:
; CHECK: %add = add nsw i32 %a, 1
%add = add i32 %a, 1
br label %exit
exit:
ret void
}
; CHECK-LABEL: @test5(
define void @test5(i32 %a) {
entry:
%cmp = icmp sle i32 %a, 2147483647
br i1 %cmp, label %bb, label %exit
bb:
; CHECK: %add = add i32 %a, 1
%add = add i32 %a, 1
br label %exit
exit:
ret void
}
; Check for a corner case where an integer value is represented with a constant
; LVILatticeValue instead of constantrange. Check that we don't fail with an
; assertion in this case.
@b = global i32 0, align 4
define void @test6(i32 %a) {
bb:
%add = add i32 %a, ptrtoint (i32* @b to i32)
ret void
}
; Check that we can gather information for conditions is the form of
; and ( i s< 100, Unknown )
; CHECK-LABEL: @test7(
define void @test7(i32 %a, i1 %flag) {
entry:
%cmp.1 = icmp slt i32 %a, 100
%cmp = and i1 %cmp.1, %flag
br i1 %cmp, label %bb, label %exit
bb:
; CHECK: %add = add nsw i32 %a, 1
%add = add i32 %a, 1
br label %exit
exit:
ret void
}
; Check that we can gather information for conditions is the form of
; and ( i s< 100, i s> 0 )
; CHECK-LABEL: @test8(
define void @test8(i32 %a) {
entry:
%cmp.1 = icmp slt i32 %a, 100
%cmp.2 = icmp sgt i32 %a, 0
%cmp = and i1 %cmp.1, %cmp.2
br i1 %cmp, label %bb, label %exit
bb:
; CHECK: %add = add nuw nsw i32 %a, 1
%add = add i32 %a, 1
br label %exit
exit:
ret void
}
; Check that for conditions is the form of cond1 && cond2 we don't mistakenly
; assume that !cond1 && !cond2 holds down to false path.
; CHECK-LABEL: @test8_neg(
define void @test8_neg(i32 %a) {
entry:
%cmp.1 = icmp sge i32 %a, 100
%cmp.2 = icmp sle i32 %a, 0
%cmp = and i1 %cmp.1, %cmp.2
br i1 %cmp, label %exit, label %bb
bb:
; CHECK: %add = add i32 %a, 1
%add = add i32 %a, 1
br label %exit
exit:
ret void
}
; Check that we can gather information for conditions is the form of
; and ( i s< 100, and (i s> 0, Unknown )
; CHECK-LABEL: @test9(
define void @test9(i32 %a, i1 %flag) {
entry:
%cmp.1 = icmp slt i32 %a, 100
%cmp.2 = icmp sgt i32 %a, 0
%cmp.3 = and i1 %cmp.2, %flag
%cmp = and i1 %cmp.1, %cmp.3
br i1 %cmp, label %bb, label %exit
bb:
; CHECK: %add = add nuw nsw i32 %a, 1
%add = add i32 %a, 1
br label %exit
exit:
ret void
}
; Check that we can gather information for conditions is the form of
; and ( i s< Unknown, ... )
; CHECK-LABEL: @test10(
define void @test10(i32 %a, i32 %b, i1 %flag) {
entry:
%cmp.1 = icmp slt i32 %a, %b
%cmp = and i1 %cmp.1, %flag
br i1 %cmp, label %bb, label %exit
bb:
; CHECK: %add = add nsw i32 %a, 1
%add = add i32 %a, 1
br label %exit
exit:
ret void
}
@limit = external global i32
; CHECK-LABEL: @test11(
define i32 @test11(i32* %p, i32 %i) {
%limit = load i32, i32* %p, !range !{i32 0, i32 2147483647}
%within.1 = icmp ugt i32 %limit, %i
%i.plus.7 = add i32 %i, 7
%within.2 = icmp ugt i32 %limit, %i.plus.7
%within = and i1 %within.1, %within.2
br i1 %within, label %then, label %else
then:
; CHECK: %i.plus.6 = add nuw nsw i32 %i, 6
%i.plus.6 = add i32 %i, 6
ret i32 %i.plus.6
else:
ret i32 0
}
; Check that we can gather information for conditions is the form of
; or ( i s>= 100, Unknown )
; CHECK-LABEL: @test12(
define void @test12(i32 %a, i1 %flag) {
entry:
%cmp.1 = icmp sge i32 %a, 100
%cmp = or i1 %cmp.1, %flag
br i1 %cmp, label %exit, label %bb
bb:
; CHECK: %add = add nsw i32 %a, 1
%add = add i32 %a, 1
br label %exit
exit:
ret void
}
; Check that we can gather information for conditions is the form of
; or ( i s>= 100, i s<= 0 )
; CHECK-LABEL: @test13(
define void @test13(i32 %a) {
entry:
%cmp.1 = icmp sge i32 %a, 100
%cmp.2 = icmp sle i32 %a, 0
%cmp = or i1 %cmp.1, %cmp.2
br i1 %cmp, label %exit, label %bb
bb:
; CHECK: %add = add nuw nsw i32 %a, 1
%add = add i32 %a, 1
br label %exit
exit:
ret void
}
; Check that for conditions is the form of cond1 || cond2 we don't mistakenly
; assume that cond1 || cond2 holds down to true path.
; CHECK-LABEL: @test13_neg(
define void @test13_neg(i32 %a) {
entry:
%cmp.1 = icmp slt i32 %a, 100
%cmp.2 = icmp sgt i32 %a, 0
%cmp = or i1 %cmp.1, %cmp.2
br i1 %cmp, label %bb, label %exit
bb:
; CHECK: %add = add i32 %a, 1
%add = add i32 %a, 1
br label %exit
exit:
ret void
}
; Check that we can gather information for conditions is the form of
; or ( i s>=100, or (i s<= 0, Unknown )
; CHECK-LABEL: @test14(
define void @test14(i32 %a, i1 %flag) {
entry:
%cmp.1 = icmp sge i32 %a, 100
%cmp.2 = icmp sle i32 %a, 0
%cmp.3 = or i1 %cmp.2, %flag
%cmp = or i1 %cmp.1, %cmp.3
br i1 %cmp, label %exit, label %bb
bb:
; CHECK: %add = add nuw nsw i32 %a, 1
%add = add i32 %a, 1
br label %exit
exit:
ret void
}
; Check that we can gather information for conditions is the form of
; or ( i s>= Unknown, ... )
; CHECK-LABEL: @test15(
define void @test15(i32 %a, i32 %b, i1 %flag) {
entry:
%cmp.1 = icmp sge i32 %a, %b
%cmp = or i1 %cmp.1, %flag
br i1 %cmp, label %exit, label %bb
bb:
; CHECK: %add = add nsw i32 %a, 1
%add = add i32 %a, 1
br label %exit
exit:
ret void
}
; single basic block loop
; because the loop exit condition is SLT, we can supplement the iv add
; (iv.next def) with an nsw.
; CHECK-LABEL: @test16(
define i32 @test16(i32* %n, i32* %a) {
preheader:
br label %loop
loop:
; CHECK: %iv.next = add nsw i32 %iv, 1
%iv = phi i32 [ 0, %preheader ], [ %iv.next, %loop ]
%acc = phi i32 [ 0, %preheader ], [ %acc.curr, %loop ]
%x = load atomic i32, i32* %a unordered, align 8
fence acquire
%acc.curr = add i32 %acc, %x
%iv.next = add i32 %iv, 1
%nval = load atomic i32, i32* %n unordered, align 8
%cmp = icmp slt i32 %iv.next, %nval
br i1 %cmp, label %loop, label %exit
exit:
ret i32 %acc.curr
}
|