llvm.org GIT mirror llvm / c9e9f6a
[NFC][InstSimplify] rewrite test added in r371537 to use non-null pointer instead I only want to ensure that %offset is non-zero there, it doesn't matter how that info is conveyed. As filed in PR43267, the assumption way does not work. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@371546 91177308-0d34-0410-b5e6-96231b3b80d8 Roman Lebedev a month ago
1 changed file(s) with 53 addition(s) and 43 deletion(s). Raw diff Collapse all Expand all
44 ; that the result is non-zero. This can be simplified just to a comparison
55 ; between the base and offset.
66
7 declare void @llvm.assume(i1)
8
9 define i1 @t0(i8 %base, i8 %offset) {
7 define i1 @t0(i64 %base, i64* nonnull %offsetptr) {
108 ; CHECK-LABEL: @t0(
11 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[OFFSET:%.*]], 0
12 ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
13 ; CHECK-NEXT: [[ADJUSTED:%.*]] = sub i8 [[BASE:%.*]], [[OFFSET]]
14 ; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp uge i8 [[ADJUSTED]], [[BASE]]
15 ; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp ne i8 [[ADJUSTED]], 0
9 ; CHECK-NEXT: [[OFFSET:%.*]] = ptrtoint i64* [[OFFSETPTR:%.*]] to i64
10 ; CHECK-NEXT: [[ADJUSTED:%.*]] = sub i64 [[BASE:%.*]], [[OFFSET]]
11 ; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp uge i64 [[ADJUSTED]], [[BASE]]
12 ; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp ne i64 [[ADJUSTED]], 0
1613 ; CHECK-NEXT: [[R:%.*]] = and i1 [[NOT_NULL]], [[NO_UNDERFLOW]]
1714 ; CHECK-NEXT: ret i1 [[R]]
1815 ;
19 %cmp = icmp ne i8 %offset, 0
20 call void @llvm.assume(i1 %cmp)
16 %offset = ptrtoint i64* %offsetptr to i64
2117
22 %adjusted = sub i8 %base, %offset
23 %no_underflow = icmp uge i8 %adjusted, %base
24 %not_null = icmp ne i8 %adjusted, 0
18 %adjusted = sub i64 %base, %offset
19 %no_underflow = icmp uge i64 %adjusted, %base
20 %not_null = icmp ne i64 %adjusted, 0
2521 %r = and i1 %not_null, %no_underflow
2622 ret i1 %r
2723 }
2824
29 define i1 @t1(i8 %base, i8 %offset) {
25 define i1 @t1(i64 %base, i64* nonnull %offsetptr) {
3026 ; CHECK-LABEL: @t1(
31 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[OFFSET:%.*]], 0
32 ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
33 ; CHECK-NEXT: [[ADJUSTED:%.*]] = sub i8 [[BASE:%.*]], [[OFFSET]]
34 ; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp ult i8 [[ADJUSTED]], [[BASE]]
35 ; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp eq i8 [[ADJUSTED]], 0
27 ; CHECK-NEXT: [[OFFSET:%.*]] = ptrtoint i64* [[OFFSETPTR:%.*]] to i64
28 ; CHECK-NEXT: [[ADJUSTED:%.*]] = sub i64 [[BASE:%.*]], [[OFFSET]]
29 ; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp ult i64 [[ADJUSTED]], [[BASE]]
30 ; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp eq i64 [[ADJUSTED]], 0
3631 ; CHECK-NEXT: [[R:%.*]] = or i1 [[NOT_NULL]], [[NO_UNDERFLOW]]
3732 ; CHECK-NEXT: ret i1 [[R]]
3833 ;
39 %cmp = icmp ne i8 %offset, 0
40 call void @llvm.assume(i1 %cmp)
34 %offset = ptrtoint i64* %offsetptr to i64
4135
42 %adjusted = sub i8 %base, %offset
43 %no_underflow = icmp ult i8 %adjusted, %base
44 %not_null = icmp eq i8 %adjusted, 0
36 %adjusted = sub i64 %base, %offset
37 %no_underflow = icmp ult i64 %adjusted, %base
38 %not_null = icmp eq i64 %adjusted, 0
4539 %r = or i1 %not_null, %no_underflow
4640 ret i1 %r
4741 }
4842
49 define i1 @t2_commutative(i8 %base, i8 %offset) {
43 define i1 @t2_commutative(i64 %base, i64* nonnull %offsetptr) {
5044 ; CHECK-LABEL: @t2_commutative(
51 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[OFFSET:%.*]], 0
52 ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
53 ; CHECK-NEXT: [[ADJUSTED:%.*]] = sub i8 [[BASE:%.*]], [[OFFSET]]
54 ; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp ule i8 [[BASE]], [[ADJUSTED]]
55 ; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp ne i8 [[ADJUSTED]], 0
45 ; CHECK-NEXT: [[OFFSET:%.*]] = ptrtoint i64* [[OFFSETPTR:%.*]] to i64
46 ; CHECK-NEXT: [[ADJUSTED:%.*]] = sub i64 [[BASE:%.*]], [[OFFSET]]
47 ; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp ule i64 [[BASE]], [[ADJUSTED]]
48 ; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp ne i64 [[ADJUSTED]], 0
5649 ; CHECK-NEXT: [[R:%.*]] = and i1 [[NOT_NULL]], [[NO_UNDERFLOW]]
5750 ; CHECK-NEXT: ret i1 [[R]]
5851 ;
59 %cmp = icmp ne i8 %offset, 0
60 call void @llvm.assume(i1 %cmp)
52 %offset = ptrtoint i64* %offsetptr to i64
6153
62 %adjusted = sub i8 %base, %offset
63 %no_underflow = icmp ule i8 %base, %adjusted
64 %not_null = icmp ne i8 %adjusted, 0
54 %adjusted = sub i64 %base, %offset
55 %no_underflow = icmp ule i64 %base, %adjusted
56 %not_null = icmp ne i64 %adjusted, 0
6557 %r = and i1 %not_null, %no_underflow
6658 ret i1 %r
6759 }
6860
61 define i1 @t3_commutative(i64 %base, i64* nonnull %offsetptr) {
62 ; CHECK-LABEL: @t3_commutative(
63 ; CHECK-NEXT: [[OFFSET:%.*]] = ptrtoint i64* [[OFFSETPTR:%.*]] to i64
64 ; CHECK-NEXT: [[ADJUSTED:%.*]] = sub i64 [[BASE:%.*]], [[OFFSET]]
65 ; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp ugt i64 [[BASE]], [[ADJUSTED]]
66 ; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp eq i64 [[ADJUSTED]], 0
67 ; CHECK-NEXT: [[R:%.*]] = or i1 [[NOT_NULL]], [[NO_UNDERFLOW]]
68 ; CHECK-NEXT: ret i1 [[R]]
69 ;
70 %offset = ptrtoint i64* %offsetptr to i64
71
72 %adjusted = sub i64 %base, %offset
73 %no_underflow = icmp ugt i64 %base, %adjusted
74 %not_null = icmp eq i64 %adjusted, 0
75 %r = or i1 %not_null, %no_underflow
76 ret i1 %r
77 }
78
6979 ; We don't know that offset is non-zero, so we can't fold.
70 define i1 @t3_bad(i8 %base, i8 %offset) {
71 ; CHECK-LABEL: @t3_bad(
72 ; CHECK-NEXT: [[ADJUSTED:%.*]] = sub i8 [[BASE:%.*]], [[OFFSET:%.*]]
73 ; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp uge i8 [[ADJUSTED]], [[BASE]]
74 ; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp ne i8 [[ADJUSTED]], 0
80 define i1 @t4_bad(i64 %base, i64 %offset) {
81 ; CHECK-LABEL: @t4_bad(
82 ; CHECK-NEXT: [[ADJUSTED:%.*]] = sub i64 [[BASE:%.*]], [[OFFSET:%.*]]
83 ; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp uge i64 [[ADJUSTED]], [[BASE]]
84 ; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp ne i64 [[ADJUSTED]], 0
7585 ; CHECK-NEXT: [[R:%.*]] = and i1 [[NOT_NULL]], [[NO_UNDERFLOW]]
7686 ; CHECK-NEXT: ret i1 [[R]]
7787 ;
78 %adjusted = sub i8 %base, %offset
79 %no_underflow = icmp uge i8 %adjusted, %base
80 %not_null = icmp ne i8 %adjusted, 0
88 %adjusted = sub i64 %base, %offset
89 %no_underflow = icmp uge i64 %adjusted, %base
90 %not_null = icmp ne i64 %adjusted, 0
8191 %r = and i1 %not_null, %no_underflow
8292 ret i1 %r
8393 }