post-inc-range.ll
7.2 KB
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
; RUN: opt < %s -indvars -indvars-post-increment-ranges -S | FileCheck %s
target datalayout = "p:64:64:64-n32:64"
; When the IV in this loop is widened we want to widen this use as well:
; icmp slt i32 %i.inc, %limit
; In order to do this indvars need to prove that the narrow IV def (%i.inc)
; is not-negative from the range check inside of the loop.
define void @test(i32* %base, i32 %limit, i32 %start) {
; CHECK-LABEL: @test(
; CHECK-NOT: trunc
for.body.lr.ph:
br label %for.body
for.body:
%i = phi i32 [ %start, %for.body.lr.ph ], [ %i.inc, %for.inc ]
%within_limits = icmp ult i32 %i, 64
br i1 %within_limits, label %continue, label %for.end
continue:
%i.i64 = zext i32 %i to i64
%arrayidx = getelementptr inbounds i32, i32* %base, i64 %i.i64
%val = load i32, i32* %arrayidx, align 4
br label %for.inc
for.inc:
%i.inc = add nsw nuw i32 %i, 1
%cmp = icmp slt i32 %i.inc, %limit
br i1 %cmp, label %for.body, label %for.end
for.end:
br label %exit
exit:
ret void
}
define void @test_false_edge(i32* %base, i32 %limit, i32 %start) {
; CHECK-LABEL: @test_false_edge(
; CHECK-NOT: trunc
for.body.lr.ph:
br label %for.body
for.body:
%i = phi i32 [ %start, %for.body.lr.ph ], [ %i.inc, %for.inc ]
%out_of_bounds = icmp ugt i32 %i, 64
br i1 %out_of_bounds, label %for.end, label %continue
continue:
%i.i64 = zext i32 %i to i64
%arrayidx = getelementptr inbounds i32, i32* %base, i64 %i.i64
%val = load i32, i32* %arrayidx, align 4
br label %for.inc
for.inc:
%i.inc = add nsw nuw i32 %i, 1
%cmp = icmp slt i32 %i.inc, %limit
br i1 %cmp, label %for.body, label %for.end
for.end:
br label %exit
exit:
ret void
}
define void @test_range_metadata(i32* %array_length_ptr, i32* %base,
i32 %limit, i32 %start) {
; CHECK-LABEL: @test_range_metadata(
; CHECK-NOT: trunc
for.body.lr.ph:
br label %for.body
for.body:
%i = phi i32 [ %start, %for.body.lr.ph ], [ %i.inc, %for.inc ]
%array_length = load i32, i32* %array_length_ptr, !range !{i32 0, i32 64 }
%within_limits = icmp ult i32 %i, %array_length
br i1 %within_limits, label %continue, label %for.end
continue:
%i.i64 = zext i32 %i to i64
%arrayidx = getelementptr inbounds i32, i32* %base, i64 %i.i64
%val = load i32, i32* %arrayidx, align 4
br label %for.inc
for.inc:
%i.inc = add nsw nuw i32 %i, 1
%cmp = icmp slt i32 %i.inc, %limit
br i1 %cmp, label %for.body, label %for.end
for.end:
br label %exit
exit:
ret void
}
; Negative version of the test above, we don't know anything about
; array_length_ptr range.
define void @test_neg(i32* %array_length_ptr, i32* %base,
i32 %limit, i32 %start) {
; CHECK-LABEL: @test_neg(
; CHECK: trunc i64
for.body.lr.ph:
br label %for.body
for.body:
%i = phi i32 [ %start, %for.body.lr.ph ], [ %i.inc, %for.inc ]
%array_length = load i32, i32* %array_length_ptr
%within_limits = icmp ult i32 %i, %array_length
br i1 %within_limits, label %continue, label %for.end
continue:
%i.i64 = zext i32 %i to i64
%arrayidx = getelementptr inbounds i32, i32* %base, i64 %i.i64
%val = load i32, i32* %arrayidx, align 4
br label %for.inc
for.inc:
%i.inc = add nsw nuw i32 %i, 1
%cmp = icmp slt i32 %i.inc, %limit
br i1 %cmp, label %for.body, label %for.end
for.end:
br label %exit
exit:
ret void
}
define void @test_transitive_use(i32* %base, i32 %limit, i32 %start) {
; CHECK-LABEL: @test_transitive_use(
; CHECK-NOT: trunc
; CHECK: %result = icmp slt i64
for.body.lr.ph:
br label %for.body
for.body:
%i = phi i32 [ %start, %for.body.lr.ph ], [ %i.inc, %for.inc ]
%within_limits = icmp ult i32 %i, 64
br i1 %within_limits, label %continue, label %for.end
continue:
%i.mul.3 = mul nsw nuw i32 %i, 3
%mul_within = icmp ult i32 %i.mul.3, 64
br i1 %mul_within, label %guarded, label %continue.2
guarded:
%i.mul.3.inc = add nsw nuw i32 %i.mul.3, 1
%result = icmp slt i32 %i.mul.3.inc, %limit
br i1 %result, label %continue.2, label %for.end
continue.2:
%i.i64 = zext i32 %i to i64
%arrayidx = getelementptr inbounds i32, i32* %base, i64 %i.i64
%val = load i32, i32* %arrayidx, align 4
br label %for.inc
for.inc:
%i.inc = add nsw nuw i32 %i, 1
%cmp = icmp slt i32 %i.inc, %limit
br i1 %cmp, label %for.body, label %for.end
for.end:
br label %exit
exit:
ret void
}
declare void @llvm.experimental.guard(i1, ...)
define void @test_guard_one_bb(i32* %base, i32 %limit, i32 %start) {
; CHECK-LABEL: @test_guard_one_bb(
; CHECK-NOT: trunc
; CHECK-NOT: icmp slt i32
for.body.lr.ph:
br label %for.body
for.body:
%i = phi i32 [ %start, %for.body.lr.ph ], [ %i.inc, %for.body ]
%within_limits = icmp ult i32 %i, 64
%i.i64 = zext i32 %i to i64
%arrayidx = getelementptr inbounds i32, i32* %base, i64 %i.i64
%val = load i32, i32* %arrayidx, align 4
call void(i1, ...) @llvm.experimental.guard(i1 %within_limits) [ "deopt"() ]
%i.inc = add nsw nuw i32 %i, 1
%cmp = icmp slt i32 %i.inc, %limit
br i1 %cmp, label %for.body, label %for.end
for.end:
br label %exit
exit:
ret void
}
define void @test_guard_in_the_same_bb(i32* %base, i32 %limit, i32 %start) {
; CHECK-LABEL: @test_guard_in_the_same_bb(
; CHECK-NOT: trunc
; CHECK-NOT: icmp slt i32
for.body.lr.ph:
br label %for.body
for.body:
%i = phi i32 [ %start, %for.body.lr.ph ], [ %i.inc, %for.inc ]
%within_limits = icmp ult i32 %i, 64
%i.i64 = zext i32 %i to i64
%arrayidx = getelementptr inbounds i32, i32* %base, i64 %i.i64
%val = load i32, i32* %arrayidx, align 4
br label %for.inc
for.inc:
call void(i1, ...) @llvm.experimental.guard(i1 %within_limits) [ "deopt"() ]
%i.inc = add nsw nuw i32 %i, 1
%cmp = icmp slt i32 %i.inc, %limit
br i1 %cmp, label %for.body, label %for.end
for.end:
br label %exit
exit:
ret void
}
define void @test_guard_in_idom(i32* %base, i32 %limit, i32 %start) {
; CHECK-LABEL: @test_guard_in_idom(
; CHECK-NOT: trunc
; CHECK-NOT: icmp slt i32
for.body.lr.ph:
br label %for.body
for.body:
%i = phi i32 [ %start, %for.body.lr.ph ], [ %i.inc, %for.inc ]
%within_limits = icmp ult i32 %i, 64
call void(i1, ...) @llvm.experimental.guard(i1 %within_limits) [ "deopt"() ]
%i.i64 = zext i32 %i to i64
%arrayidx = getelementptr inbounds i32, i32* %base, i64 %i.i64
%val = load i32, i32* %arrayidx, align 4
br label %for.inc
for.inc:
%i.inc = add nsw nuw i32 %i, 1
%cmp = icmp slt i32 %i.inc, %limit
br i1 %cmp, label %for.body, label %for.end
for.end:
br label %exit
exit:
ret void
}
define void @test_guard_merge_ranges(i32* %base, i32 %limit, i32 %start) {
; CHECK-LABEL: @test_guard_merge_ranges(
; CHECK-NOT: trunc
; CHECK-NOT: icmp slt i32
for.body.lr.ph:
br label %for.body
for.body:
%i = phi i32 [ %start, %for.body.lr.ph ], [ %i.inc, %for.body ]
%within_limits.1 = icmp ult i32 %i, 64
call void(i1, ...) @llvm.experimental.guard(i1 %within_limits.1) [ "deopt"() ]
%within_limits.2 = icmp ult i32 %i, 2147483647
call void(i1, ...) @llvm.experimental.guard(i1 %within_limits.2) [ "deopt"() ]
%i.i64 = zext i32 %i to i64
%arrayidx = getelementptr inbounds i32, i32* %base, i64 %i.i64
%val = load i32, i32* %arrayidx, align 4
%i.inc = add nsw nuw i32 %i, 1
%cmp = icmp slt i32 %i.inc, %limit
br i1 %cmp, label %for.body, label %for.end
for.end:
br label %exit
exit:
ret void
}