Skip to content

Commit a3d1212

Browse files
committed
Test for use range attribute to constant fold comparisons with constant values.
1 parent 5b4c350 commit a3d1212

File tree

1 file changed

+151
-5
lines changed

1 file changed

+151
-5
lines changed

llvm/test/Transforms/InstCombine/icmp-range.ll

Lines changed: 151 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ define i1 @test_two_ranges(ptr nocapture readonly %arg1, ptr nocapture readonly
149149
ret i1 %rval
150150
}
151151

152+
; Values' ranges overlap each other, so it can not be simplified.
153+
define i1 @test_two_attribute_ranges(i32 range(i32 5, 10) %arg1, i32 range(i32 8, 16) %arg2) {
154+
; CHECK-LABEL: @test_two_attribute_ranges(
155+
; CHECK-NEXT: [[RVAL:%.*]] = icmp ult i32 [[ARG1:%.*]], [[ARG2:%.*]]
156+
; CHECK-NEXT: ret i1 [[RVAL]]
157+
;
158+
%rval = icmp ult i32 %arg2, %arg1
159+
ret i1 %rval
160+
}
161+
152162
; Values' ranges do not overlap each other, so it can simplified to false.
153163
define i1 @test_two_ranges2(ptr nocapture readonly %arg1, ptr nocapture readonly %arg2) {
154164
; CHECK-LABEL: @test_two_ranges2(
@@ -160,6 +170,40 @@ define i1 @test_two_ranges2(ptr nocapture readonly %arg1, ptr nocapture readonly
160170
ret i1 %rval
161171
}
162172

173+
; Values' ranges do not overlap each other, so it can simplified to false.
174+
define i1 @test_two_argument_ranges(i32 range(i32 1, 6) %arg1, i32 range(i32 8, 16) %arg2) {
175+
; CHECK-LABEL: @test_two_argument_ranges(
176+
; CHECK-NEXT: [[RVAL:%.*]] = icmp ult i32 [[ARG2:%.*]], [[ARG1:%.*]]
177+
; CHECK-NEXT: ret i1 [[RVAL]]
178+
;
179+
%rval = icmp ult i32 %arg2, %arg1
180+
ret i1 %rval
181+
}
182+
183+
; Values' ranges do not overlap each other, so it can simplified to false.
184+
define i1 @test_one_range_and_one_argument_range(ptr nocapture readonly %arg1, i32 range(i32 8, 16) %arg2) {
185+
; CHECK-LABEL: @test_one_range_and_one_argument_range(
186+
; CHECK-NEXT: [[VAL1:%.*]] = load i32, ptr [[ARG1:%.*]], align 4, !range [[RNG2]]
187+
; CHECK-NEXT: [[RVAL:%.*]] = icmp ugt i32 [[VAL1]], [[ARG2:%.*]]
188+
; CHECK-NEXT: ret i1 [[RVAL]]
189+
;
190+
%val1 = load i32, ptr %arg1, !range !0
191+
%rval = icmp ult i32 %arg2, %val1
192+
ret i1 %rval
193+
}
194+
195+
; Values' ranges do not overlap each other, so it can simplified to false.
196+
define i1 @test_one_argument_range_and_one_range(i32 range(i32 1, 6) %arg1, ptr nocapture readonly %arg2) {
197+
; CHECK-LABEL: @test_one_argument_range_and_one_range(
198+
; CHECK-NEXT: [[VAL1:%.*]] = load i32, ptr [[ARG2:%.*]], align 4, !range [[RNG5]]
199+
; CHECK-NEXT: [[RVAL:%.*]] = icmp ult i32 [[VAL1]], [[ARG1:%.*]]
200+
; CHECK-NEXT: ret i1 [[RVAL]]
201+
;
202+
%val1 = load i32, ptr %arg2, !range !6
203+
%rval = icmp ult i32 %val1, %arg1
204+
ret i1 %rval
205+
}
206+
163207
; Values' ranges do not overlap each other, so it can simplified to true.
164208
define i1 @test_two_ranges3(ptr nocapture readonly %arg1, ptr nocapture readonly %arg2) {
165209
; CHECK-LABEL: @test_two_ranges3(
@@ -186,8 +230,8 @@ define <2 x i1> @test_two_ranges_vec(ptr nocapture readonly %arg1, ptr nocapture
186230
}
187231

188232
; Values' ranges do not overlap each other, so it can simplified to false.
189-
define <2 x i1> @test_two_ranges_vec_true(ptr nocapture readonly %arg1, ptr nocapture readonly %arg2) {
190-
; CHECK-LABEL: @test_two_ranges_vec_true(
233+
define <2 x i1> @test_two_ranges_vec_false(ptr nocapture readonly %arg1, ptr nocapture readonly %arg2) {
234+
; CHECK-LABEL: @test_two_ranges_vec_false(
191235
; CHECK-NEXT: ret <2 x i1> zeroinitializer
192236
;
193237
%val1 = load <2 x i32>, ptr %arg1, !range !0
@@ -196,9 +240,9 @@ define <2 x i1> @test_two_ranges_vec_true(ptr nocapture readonly %arg1, ptr noca
196240
ret <2 x i1> %rval
197241
}
198242

199-
; Values' ranges do not overlap each other, so it can simplified to false.
200-
define <2 x i1> @test_two_ranges_vec_false(ptr nocapture readonly %arg1, ptr nocapture readonly %arg2) {
201-
; CHECK-LABEL: @test_two_ranges_vec_false(
243+
; Values' ranges do not overlap each other, so it can simplified to true.
244+
define <2 x i1> @test_two_ranges_vec_true(ptr nocapture readonly %arg1, ptr nocapture readonly %arg2) {
245+
; CHECK-LABEL: @test_two_ranges_vec_true(
202246
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
203247
;
204248
%val1 = load <2 x i32>, ptr %arg1, !range !0
@@ -207,6 +251,108 @@ define <2 x i1> @test_two_ranges_vec_false(ptr nocapture readonly %arg1, ptr noc
207251
ret <2 x i1> %rval
208252
}
209253

254+
; Values' ranges overlap each other, so it can not be simplified.
255+
define <2 x i1> @test_two_argument_ranges_vec(<2 x i32> range(i32 5, 10) %arg1, <2 x i32> range(i32 8, 16) %arg2) {
256+
; CHECK-LABEL: @test_two_argument_ranges_vec(
257+
; CHECK-NEXT: [[RVAL:%.*]] = icmp ult <2 x i32> [[VAL2:%.*]], [[VAL1:%.*]]
258+
; CHECK-NEXT: ret <2 x i1> [[RVAL]]
259+
;
260+
%rval = icmp ult <2 x i32> %arg2, %arg1
261+
ret <2 x i1> %rval
262+
}
263+
264+
; Values' ranges do not overlap each other, so it can simplified to false.
265+
define <2 x i1> @test_two_argument_ranges_vec_false(<2 x i32> range(i32 1, 6) %arg1, <2 x i32> range(i32 8, 16) %arg2) {
266+
; CHECK-LABEL: @test_two_argument_ranges_vec_false(
267+
; CHECK-NEXT: [[RVAL:%.*]] = icmp ult <2 x i32> [[ARG2:%.*]], [[ARG1:%.*]]
268+
; CHECK-NEXT: ret <2 x i1> [[RVAL]]
269+
;
270+
%rval = icmp ult <2 x i32> %arg2, %arg1
271+
ret <2 x i1> %rval
272+
}
273+
274+
; Values' ranges do not overlap each other, so it can simplified to true.
275+
define <2 x i1> @test_two_argument_ranges_vec_true(<2 x i32> range(i32 1, 6) %arg1, <2 x i32> range(i32 8, 16) %arg2) {
276+
; CHECK-LABEL: @test_two_argument_ranges_vec_true(
277+
; CHECK-NEXT: [[RVAL:%.*]] = icmp ugt <2 x i32> [[ARG2:%.*]], [[ARG1:%.*]]
278+
; CHECK-NEXT: ret <2 x i1> [[RVAL]]
279+
;
280+
%rval = icmp ugt <2 x i32> %arg2, %arg1
281+
ret <2 x i1> %rval
282+
}
283+
284+
declare i32 @create_range1()
285+
declare range(i32 8, 16) i32 @create_range2()
286+
declare range(i32 1, 6) i32 @create_range3()
287+
288+
; Values' ranges overlap each other, so it can not be simplified.
289+
define i1 @test_two_return_attribute_ranges_not_simplified() {
290+
; CHECK-LABEL: @test_two_return_attribute_ranges_not_simplified(
291+
; CHECK-NEXT: [[ARG2:%.*]] = call range(i32 5, 10) i32 @create_range1()
292+
; CHECK-NEXT: [[ARG1:%.*]] = call i32 @create_range2()
293+
; CHECK-NEXT: [[RVAL:%.*]] = icmp ult i32 [[ARG1]], [[ARG2]]
294+
; CHECK-NEXT: ret i1 [[RVAL]]
295+
;
296+
%val1 = call range(i32 5, 10) i32 @create_range1()
297+
%val2 = call i32 @create_range2()
298+
%rval = icmp ult i32 %val2, %val1
299+
ret i1 %rval
300+
}
301+
302+
; Values' ranges do not overlap each other, so it can simplified to false.
303+
define i1 @test_two_return_attribute_ranges_one_in_call() {
304+
; CHECK-LABEL: @test_two_return_attribute_ranges_one_in_call(
305+
; CHECK-NEXT: [[VAL1:%.*]] = call range(i32 1, 6) i32 @create_range1()
306+
; CHECK-NEXT: [[ARG1:%.*]] = call i32 @create_range2()
307+
; CHECK-NEXT: [[RVAL:%.*]] = icmp ult i32 [[ARG1]], [[VAL1]]
308+
; CHECK-NEXT: ret i1 [[RVAL]]
309+
;
310+
%val1 = call range(i32 1, 6) i32 @create_range1()
311+
%val2 = call i32 @create_range2()
312+
%rval = icmp ult i32 %val2, %val1
313+
ret i1 %rval
314+
}
315+
316+
; Values' ranges do not overlap each other, so it can simplified to false.
317+
define i1 @test_two_return_attribute_ranges() {
318+
; CHECK-LABEL: @test_two_return_attribute_ranges(
319+
; CHECK-NEXT: [[VAL1:%.*]] = call i32 @create_range3()
320+
; CHECK-NEXT: [[ARG1:%.*]] = call i32 @create_range2()
321+
; CHECK-NEXT: [[RVAL:%.*]] = icmp ult i32 [[ARG1]], [[VAL1]]
322+
; CHECK-NEXT: ret i1 [[RVAL]]
323+
;
324+
%val1 = call i32 @create_range3()
325+
%val2 = call i32 @create_range2()
326+
%rval = icmp ult i32 %val2, %val1
327+
ret i1 %rval
328+
}
329+
330+
; Values' ranges do not overlap each other, so it can simplified to false.
331+
define i1 @test_one_return_argument_and_one_argument_range(i32 range(i32 8, 16) %arg1) {
332+
; CHECK-LABEL: @test_one_return_argument_and_one_argument_range(
333+
; CHECK-NEXT: [[VAL1:%.*]] = call i32 @create_range3()
334+
; CHECK-NEXT: [[RVAL:%.*]] = icmp ugt i32 [[VAL1]], [[ARG1:%.*]]
335+
; CHECK-NEXT: ret i1 [[RVAL]]
336+
;
337+
%val1 = call i32 @create_range3()
338+
%rval = icmp ult i32 %arg1, %val1
339+
ret i1 %rval
340+
}
341+
342+
; Values' ranges do not overlap each other, so it can simplified to false.
343+
define i1 @test_one_range_and_one_return_argument(ptr nocapture readonly %arg1) {
344+
; CHECK-LABEL: @test_one_range_and_one_return_argument(
345+
; CHECK-NEXT: [[VAL1:%.*]] = call i32 @create_range3()
346+
; CHECK-NEXT: [[VAL2:%.*]] = load i32, ptr [[ARG1:%.*]], align 4, !range [[RNG5]]
347+
; CHECK-NEXT: [[RVAL:%.*]] = icmp ult i32 [[VAL2]], [[VAL1]]
348+
; CHECK-NEXT: ret i1 [[RVAL]]
349+
;
350+
%val1 = call i32 @create_range3()
351+
%val2 = load i32, ptr %arg1, !range !6
352+
%rval = icmp ult i32 %val2, %val1
353+
ret i1 %rval
354+
}
355+
210356
define i1 @ugt_zext(i1 %b, i8 %x) {
211357
; CHECK-LABEL: @ugt_zext(
212358
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 [[X:%.*]], 0

0 commit comments

Comments
 (0)