Skip to content

Commit df32fd9

Browse files
committed
[ValueTracking] Tests with range assume bundles (NFC)
1 parent e872852 commit df32fd9

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

llvm/test/Analysis/BasicAA/range.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,18 @@ entry:
271271
ret i32 %load_
272272
}
273273

274+
; CHECK-LABEL: Function: range_assume
275+
; CHECK: MayAlias: i32* %gep1, i32* %gep2
276+
define void @range_assume(ptr %s, ptr %q) {
277+
%in_array = load i32, ptr %q
278+
call void @llvm.assume(i1 true) ["range"(i32 %in_array, i32 0, i32 2)]
279+
%gep1 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 1, i32 %in_array
280+
%gep2 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 2
281+
load i32, ptr %gep1
282+
load i32, ptr %gep2
283+
ret void
284+
}
285+
274286
declare void @llvm.assume(i1)
275287

276288
!0 = !{ i32 0, i32 2 }

llvm/test/Analysis/ValueTracking/known-non-zero.ll

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,4 +1546,56 @@ define i1 @vec_reverse_non_zero_demanded_fail(<4 x i8> %xx) {
15461546
ret i1 %r
15471547
}
15481548

1549+
define i1 @range_assume(i8 %x, i8 %y) {
1550+
; CHECK-LABEL: @range_assume(
1551+
; CHECK-NEXT: call void @llvm.assume(i1 true) [ "range"(i8 [[X:%.*]], i8 1, i8 0) ]
1552+
; CHECK-NEXT: [[OR:%.*]] = or i8 [[Y:%.*]], [[X]]
1553+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[OR]], 0
1554+
; CHECK-NEXT: ret i1 [[CMP]]
1555+
;
1556+
call void @llvm.assume(i1 true) ["range"(i8 %x, i8 1, i8 0)]
1557+
%or = or i8 %y, %x
1558+
%cmp = icmp eq i8 %or, 0
1559+
ret i1 %cmp
1560+
}
1561+
1562+
define i1 @neg_range_assum(i8 %x, i8 %y) {
1563+
; CHECK-LABEL: @neg_range_assum(
1564+
; CHECK-NEXT: call void @llvm.assume(i1 true) [ "range"(i8 [[X:%.*]], i8 -1, i8 1) ]
1565+
; CHECK-NEXT: [[OR:%.*]] = or i8 [[Y:%.*]], [[X]]
1566+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[OR]], 0
1567+
; CHECK-NEXT: ret i1 [[CMP]]
1568+
;
1569+
call void @llvm.assume(i1 true) ["range"(i8 %x, i8 -1, i8 1)]
1570+
%or = or i8 %y, %x
1571+
%cmp = icmp eq i8 %or, 0
1572+
ret i1 %cmp
1573+
}
1574+
1575+
define <2 x i1> @range_assum_vec(<2 x i8> %x, <2 x i8> %y) {
1576+
; CHECK-LABEL: @range_assum_vec(
1577+
; CHECK-NEXT: call void @llvm.assume(i1 true) [ "range"(<2 x i8> [[X:%.*]], i8 1, i8 0) ]
1578+
; CHECK-NEXT: [[OR:%.*]] = or <2 x i8> [[Y:%.*]], [[X]]
1579+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i8> [[OR]], zeroinitializer
1580+
; CHECK-NEXT: ret <2 x i1> [[CMP]]
1581+
;
1582+
call void @llvm.assume(i1 true) ["range"(<2 x i8> %x, i8 1, i8 0)]
1583+
%or = or <2 x i8> %y, %x
1584+
%cmp = icmp ne <2 x i8> %or, zeroinitializer
1585+
ret <2 x i1> %cmp
1586+
}
1587+
1588+
define <2 x i1> @neg_range_assum_vec(<2 x i8> %x, <2 x i8> %y) {
1589+
; CHECK-LABEL: @neg_range_assum_vec(
1590+
; CHECK-NEXT: call void @llvm.assume(i1 true) [ "range"(<2 x i8> [[X:%.*]], i8 -1, i8 1) ]
1591+
; CHECK-NEXT: [[OR:%.*]] = or <2 x i8> [[Y:%.*]], [[X]]
1592+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i8> [[OR]], zeroinitializer
1593+
; CHECK-NEXT: ret <2 x i1> [[CMP]]
1594+
;
1595+
call void @llvm.assume(i1 true) ["range"(<2 x i8> %x, i8 -1, i8 1)]
1596+
%or = or <2 x i8> %y, %x
1597+
%cmp = icmp ne <2 x i8> %or, zeroinitializer
1598+
ret <2 x i1> %cmp
1599+
}
1600+
15491601
declare i32 @llvm.experimental.get.vector.length.i32(i32, i32, i1)

llvm/test/Transforms/InstSimplify/shift-knownbits.ll

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,3 +499,48 @@ define <1 x i64> @bitcast_noshift_vector_wrong_type(<2 x float> %v1, <1 x i64> %
499499
%r = shl <1 x i64> %v2, %b
500500
ret <1 x i64> %r
501501
}
502+
503+
define i32 @shl_amount_is_known_bogus_range_assum(i32 %a, i32 %b) {
504+
; CHECK-LABEL: @shl_amount_is_known_bogus_range_assum(
505+
; CHECK-NEXT: call void @llvm.assume(i1 true) [ "range"(i32 [[B:%.*]], i32 32, i32 64) ]
506+
; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[A:%.*]], [[B]]
507+
; CHECK-NEXT: ret i32 [[SHL]]
508+
;
509+
call void @llvm.assume(i1 true) ["range"(i32 %b, i32 32, i32 64)]
510+
%shl = shl i32 %a, %b
511+
ret i32 %shl
512+
}
513+
514+
define i32 @neg_shl_amount_is_known_bogus_range_assum(i32 %a, i32 %b) {
515+
; CHECK-LABEL: @neg_shl_amount_is_known_bogus_range_assum(
516+
; CHECK-NEXT: call void @llvm.assume(i1 true) [ "range"(i32 [[B:%.*]], i32 0, i32 32) ]
517+
; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[A:%.*]], [[B]]
518+
; CHECK-NEXT: ret i32 [[SHL]]
519+
;
520+
call void @llvm.assume(i1 true) ["range"(i32 %b, i32 0, i32 32)]
521+
%shl = shl i32 %a, %b
522+
ret i32 %shl
523+
}
524+
525+
526+
define <2 x i32> @shl_amount_is_known_bogus_range_assum_vec(<2 x i32> %a, <2 x i32> %b) {
527+
; CHECK-LABEL: @shl_amount_is_known_bogus_range_assum_vec(
528+
; CHECK-NEXT: call void @llvm.assume(i1 true) [ "range"(<2 x i32> [[B:%.*]], i32 32, i32 64) ]
529+
; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i32> [[A:%.*]], [[B]]
530+
; CHECK-NEXT: ret <2 x i32> [[SHL]]
531+
;
532+
call void @llvm.assume(i1 true) ["range"(<2 x i32> %b, i32 32, i32 64)]
533+
%shl = shl <2 x i32> %a, %b
534+
ret <2 x i32> %shl
535+
}
536+
537+
define <2 x i32> @neg_shl_amount_is_known_bogus_range_assum_vec(<2 x i32> %a, <2 x i32> %b) {
538+
; CHECK-LABEL: @neg_shl_amount_is_known_bogus_range_assum_vec(
539+
; CHECK-NEXT: call void @llvm.assume(i1 true) [ "range"(<2 x i32> [[B:%.*]], i32 0, i32 32) ]
540+
; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i32> [[A:%.*]], [[B]]
541+
; CHECK-NEXT: ret <2 x i32> [[SHL]]
542+
;
543+
call void @llvm.assume(i1 true) ["range"(<2 x i32> %b, i32 0, i32 32)]
544+
%shl = shl <2 x i32> %a, %b
545+
ret <2 x i32> %shl
546+
}

0 commit comments

Comments
 (0)