1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt %s -instsimplify -S | FileCheck %s
4 ; Here we add unsigned two values, check that addition did not underflow AND
5 ; that the result is non-zero. This can be simplified just to a comparison
6 ; between the base and negated offset.
8 ; If we are checking that the result is not null or no underflow happened,
9 ; it is tautological (always-true).
10 define i1 @t1(i8 %x, i8 %y) {
12 ; CHECK-NEXT: ret i1 true
14 %not_null = icmp ne i8 %y, 0
15 %no_underflow = icmp ule i8 %y, %x
16 %r = or i1 %not_null, %no_underflow
19 define i1 @t2_commutative(i8 %x, i8 %y) {
20 ; CHECK-LABEL: @t2_commutative(
21 ; CHECK-NEXT: ret i1 true
23 %not_null = icmp ne i8 %y, 0
24 %no_underflow = icmp uge i8 %x, %y ; swapped
25 %r = or i1 %not_null, %no_underflow
29 define i1 @t3_commutative(i8 %x, i8 %y) {
30 ; CHECK-LABEL: @t3_commutative(
31 ; CHECK-NEXT: ret i1 true
33 %not_null = icmp ne i8 %y, 0
34 %no_underflow = icmp ule i8 %y, %x
35 %r = or i1 %no_underflow, %not_null ; swapped
38 define i1 @t4_commutative(i8 %x, i8 %y) {
39 ; CHECK-LABEL: @t4_commutative(
40 ; CHECK-NEXT: ret i1 true
42 %not_null = icmp ne i8 %y, 0
43 %no_underflow = icmp uge i8 %x, %y ; swapped
44 %r = or i1 %no_underflow, %not_null ; swapped
48 ; If we are checking that the result is null and underflow happened,
49 ; it is tautological (always-false).
50 define i1 @t5(i8 %x, i8 %y) {
52 ; CHECK-NEXT: ret i1 false
54 %not_null = icmp eq i8 %y, 0
55 %no_underflow = icmp ugt i8 %y, %x
56 %r = and i1 %not_null, %no_underflow
59 define i1 @t6_commutative(i8 %x, i8 %y) {
60 ; CHECK-LABEL: @t6_commutative(
61 ; CHECK-NEXT: ret i1 false
63 %not_null = icmp eq i8 %y, 0
64 %no_underflow = icmp ult i8 %x, %y ; swapped
65 %r = and i1 %not_null, %no_underflow
69 ; We only need to know that any of the 'add' operands is non-zero,
70 ; not necessarily the one used in the comparison.
71 define i1 @t7(i8 %x, i8 %y) {
73 ; CHECK-NEXT: ret i1 true
75 %cmp = icmp slt i8 %y, 0
76 %not_null = icmp ne i8 %y, 0
77 %no_underflow = icmp ule i8 %y, %x
78 %r = or i1 %not_null, %no_underflow
82 ; If we check that no underflow happened and that the result is null,
83 ; we can just check for null.
84 define i1 @t8(i8 %x, i8 %y) {
86 ; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp eq i8 [[Y:%.*]], 0
87 ; CHECK-NEXT: ret i1 [[NOT_NULL]]
89 %not_null = icmp eq i8 %y, 0
90 %no_underflow = icmp ule i8 %y, %x
91 %r = and i1 %not_null, %no_underflow
94 ; Likewise, if we check that result is non-null or underflow happened,
95 ; we can just check for null.
96 define i1 @t9(i8 %x, i8 %y) {
98 ; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp ne i8 [[Y:%.*]], 0
99 ; CHECK-NEXT: ret i1 [[NOT_NULL]]
101 %not_null = icmp ne i8 %y, 0
102 %no_underflow = icmp ugt i8 %y, %x
103 %r = or i1 %not_null, %no_underflow
107 ; If we check that no underflow happened or that the result is not null,
108 ; we can just check for lack of underflow.
109 define i1 @t10(i8 %x, i8 %y) {
111 ; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp ule i8 [[Y:%.*]], [[X:%.*]]
112 ; CHECK-NEXT: ret i1 [[NO_UNDERFLOW]]
114 %not_null = icmp eq i8 %y, 0
115 %no_underflow = icmp ule i8 %y, %x
116 %r = or i1 %not_null, %no_underflow
119 ; Likewise, if we check that underflow happened and that the result is not null,
120 ; we can just check for lack of underflow.
121 define i1 @t11(i8 %x, i8 %y) {
123 ; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp ugt i8 [[Y:%.*]], [[X:%.*]]
124 ; CHECK-NEXT: ret i1 [[NO_UNDERFLOW]]
126 %not_null = icmp ne i8 %y, 0
127 %no_underflow = icmp ugt i8 %y, %x
128 %r = and i1 %not_null, %no_underflow