1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=instsimplify -S < %s | FileCheck %s
4 define i1 @sdiv_neg_neg_high_bits(i8 %x, i8 %y) {
5 ; CHECK-LABEL: @sdiv_neg_neg_high_bits(
6 ; CHECK-NEXT: ret i1 false
10 %div = sdiv i8 %num, %denum
11 %and = and i8 %div, 128
12 %r = icmp eq i8 %and, 128
16 define i1 @sdiv_pos_neg_high_bits(i8 %x, i8 %y) {
17 ; CHECK-LABEL: @sdiv_pos_neg_high_bits(
18 ; CHECK-NEXT: ret i1 false
22 %denum = or i8 %y, 241
23 %div = sdiv i8 %num, %denum
24 %and = and i8 %div, 128
25 %r = icmp eq i8 %and, 0
29 define i1 @sdiv_pos_neg_high_bits_fail_maybez(i8 %x, i8 %y) {
30 ; CHECK-LABEL: @sdiv_pos_neg_high_bits_fail_maybez(
31 ; CHECK-NEXT: [[XX:%.*]] = and i8 [[X:%.*]], 127
32 ; CHECK-NEXT: [[NUM:%.*]] = or i8 [[XX]], 49
33 ; CHECK-NEXT: [[DENUM:%.*]] = or i8 [[Y:%.*]], -64
34 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i8 [[NUM]], [[DENUM]]
35 ; CHECK-NEXT: [[AND:%.*]] = and i8 [[DIV]], -128
36 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], 0
37 ; CHECK-NEXT: ret i1 [[R]]
41 %denum = or i8 %y, 192
42 %div = sdiv i8 %num, %denum
43 %and = and i8 %div, 128
44 %r = icmp eq i8 %and, 0
48 define i1 @sdiv_exact_pos_neg_high_bits(i8 %x, i8 %y) {
49 ; CHECK-LABEL: @sdiv_exact_pos_neg_high_bits(
50 ; CHECK-NEXT: ret i1 false
54 %denum = or i8 %y, 192
55 %div = sdiv exact i8 %num, %denum
56 %and = and i8 %div, 128
57 %r = icmp eq i8 %and, 0
61 define i1 @sdiv_neg_pos_high_bits(i8 %x, i8 %y) {
62 ; CHECK-LABEL: @sdiv_neg_pos_high_bits(
63 ; CHECK-NEXT: ret i1 false
69 %div = sdiv i8 %num, %denum
70 %and = and i8 %div, 128
71 %r = icmp eq i8 %and, 0
75 define i1 @sdiv_neg_pos_high_bits_fail_maybez(i8 %x, i8 %y) {
76 ; CHECK-LABEL: @sdiv_neg_pos_high_bits_fail_maybez(
77 ; CHECK-NEXT: [[NUM:%.*]] = or i8 [[X:%.*]], -128
78 ; CHECK-NEXT: [[YY:%.*]] = and i8 [[Y:%.*]], 15
79 ; CHECK-NEXT: [[DENUM:%.*]] = or i8 [[YY]], 9
80 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i8 [[NUM]], [[DENUM]]
81 ; CHECK-NEXT: [[AND:%.*]] = and i8 [[DIV]], -128
82 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], 0
83 ; CHECK-NEXT: ret i1 [[R]]
88 %div = sdiv i8 %num, %denum
89 %and = and i8 %div, 128
90 %r = icmp eq i8 %and, 0
94 define i1 @sdiv_exact_odd_odd(i8 %x, i8 %y) {
95 ; CHECK-LABEL: @sdiv_exact_odd_odd(
96 ; CHECK-NEXT: ret i1 false
100 %div = sdiv exact i8 %num, %denum
101 %and = and i8 %div, 1
102 %r = icmp eq i8 %and, 0
106 define i1 @sdiv_exact_even_odd(i8 %x, i8 %y) {
107 ; CHECK-LABEL: @sdiv_exact_even_odd(
108 ; CHECK-NEXT: ret i1 false
112 %div = sdiv exact i8 %num, %denum
113 %and = and i8 %div, 1
114 %r = icmp eq i8 %and, 1
118 define i1 @sdiv_exact_even_even_fail_unknown(i8 %x, i8 %y) {
119 ; CHECK-LABEL: @sdiv_exact_even_even_fail_unknown(
120 ; CHECK-NEXT: [[NUM:%.*]] = and i8 [[X:%.*]], -2
121 ; CHECK-NEXT: [[DENUM:%.*]] = and i8 [[Y:%.*]], -2
122 ; CHECK-NEXT: [[DIV:%.*]] = sdiv exact i8 [[NUM]], [[DENUM]]
123 ; CHECK-NEXT: [[AND:%.*]] = and i8 [[DIV]], 1
124 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], 1
125 ; CHECK-NEXT: ret i1 [[R]]
128 %denum = and i8 %y, -2
129 %div = sdiv exact i8 %num, %denum
130 %and = and i8 %div, 1
131 %r = icmp eq i8 %and, 1
135 define i1 @sdiv_exact_even_even_fail_unknown2(i8 %x, i8 %y) {
136 ; CHECK-LABEL: @sdiv_exact_even_even_fail_unknown2(
137 ; CHECK-NEXT: [[NUM:%.*]] = and i8 [[X:%.*]], -2
138 ; CHECK-NEXT: [[DENUM:%.*]] = and i8 [[Y:%.*]], -2
139 ; CHECK-NEXT: [[DIV:%.*]] = sdiv exact i8 [[NUM]], [[DENUM]]
140 ; CHECK-NEXT: [[AND:%.*]] = and i8 [[DIV]], 1
141 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], 0
142 ; CHECK-NEXT: ret i1 [[R]]
145 %denum = and i8 %y, -2
146 %div = sdiv exact i8 %num, %denum
147 %and = and i8 %div, 1
148 %r = icmp eq i8 %and, 0
152 define i1 @udiv_high_bits(i8 %x, i8 %y) {
153 ; CHECK-LABEL: @udiv_high_bits(
154 ; CHECK-NEXT: ret i1 false
156 %num = and i8 %x, 129
157 %denum = or i8 %y, 31
158 %div = udiv i8 %num, %denum
159 %and = and i8 %div, 8
160 %r = icmp eq i8 %and, 8
164 define i1 @udiv_exact_odd_odd(i8 %x, i8 %y) {
165 ; CHECK-LABEL: @udiv_exact_odd_odd(
166 ; CHECK-NEXT: ret i1 false
170 %div = udiv exact i8 %num, %denum
171 %and = and i8 %div, 1
172 %r = icmp eq i8 %and, 0
176 define i1 @udiv_exact_even_odd(i8 %x, i8 %y) {
177 ; CHECK-LABEL: @udiv_exact_even_odd(
178 ; CHECK-NEXT: ret i1 false
182 %div = udiv exact i8 %num, %denum
183 %and = and i8 %div, 1
184 %r = icmp eq i8 %and, 1
188 define i1 @udiv_exact_even_even_fail_unknown(i8 %x, i8 %y) {
189 ; CHECK-LABEL: @udiv_exact_even_even_fail_unknown(
190 ; CHECK-NEXT: [[NUM:%.*]] = and i8 [[X:%.*]], -2
191 ; CHECK-NEXT: [[DENUM:%.*]] = and i8 [[Y:%.*]], -2
192 ; CHECK-NEXT: [[DIV:%.*]] = udiv exact i8 [[NUM]], [[DENUM]]
193 ; CHECK-NEXT: [[AND:%.*]] = and i8 [[DIV]], 1
194 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], 1
195 ; CHECK-NEXT: ret i1 [[R]]
198 %denum = and i8 %y, -2
199 %div = udiv exact i8 %num, %denum
200 %and = and i8 %div, 1
201 %r = icmp eq i8 %and, 1
205 define i1 @udiv_exact_even_even_fail_unknown2(i8 %x, i8 %y) {
206 ; CHECK-LABEL: @udiv_exact_even_even_fail_unknown2(
207 ; CHECK-NEXT: [[NUM:%.*]] = and i8 [[X:%.*]], -2
208 ; CHECK-NEXT: [[DENUM:%.*]] = and i8 [[Y:%.*]], -2
209 ; CHECK-NEXT: [[DIV:%.*]] = udiv exact i8 [[NUM]], [[DENUM]]
210 ; CHECK-NEXT: [[AND:%.*]] = and i8 [[DIV]], 1
211 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], 0
212 ; CHECK-NEXT: ret i1 [[R]]
215 %denum = and i8 %y, -2
216 %div = udiv exact i8 %num, %denum
217 %and = and i8 %div, 1
218 %r = icmp eq i8 %and, 0