1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instsimplify -S | FileCheck %s
4 define i32 @foo(i32 %x) {
6 ; CHECK-NEXT: [[O:%.*]] = and i32 %x, 1
7 ; CHECK-NEXT: [[N:%.*]] = add i32 [[O]], -1
8 ; CHECK-NEXT: ret i32 [[N]]
16 define i1 @exact_lshr_eq_both_zero(i8 %a) {
17 ; CHECK-LABEL: @exact_lshr_eq_both_zero(
18 ; CHECK-NEXT: ret i1 true
20 %shr = lshr exact i8 0, %a
21 %cmp = icmp eq i8 %shr, 0
25 define i1 @exact_ashr_eq_both_zero(i8 %a) {
26 ; CHECK-LABEL: @exact_ashr_eq_both_zero(
27 ; CHECK-NEXT: ret i1 true
29 %shr = ashr exact i8 0, %a
30 %cmp = icmp eq i8 %shr, 0
34 define i1 @nonexact_ashr_eq_both_zero(i8 %a) {
35 ; CHECK-LABEL: @nonexact_ashr_eq_both_zero(
36 ; CHECK-NEXT: ret i1 true
39 %cmp = icmp eq i8 %shr, 0
43 define i1 @exact_lshr_ne_both_zero(i8 %a) {
44 ; CHECK-LABEL: @exact_lshr_ne_both_zero(
45 ; CHECK-NEXT: ret i1 false
47 %shr = lshr exact i8 0, %a
48 %cmp = icmp ne i8 %shr, 0
52 define i1 @exact_ashr_ne_both_zero(i8 %a) {
53 ; CHECK-LABEL: @exact_ashr_ne_both_zero(
54 ; CHECK-NEXT: ret i1 false
56 %shr = ashr exact i8 0, %a
57 %cmp = icmp ne i8 %shr, 0
61 define i1 @nonexact_lshr_ne_both_zero(i8 %a) {
62 ; CHECK-LABEL: @nonexact_lshr_ne_both_zero(
63 ; CHECK-NEXT: ret i1 false
66 %cmp = icmp ne i8 %shr, 0
70 define i1 @nonexact_ashr_ne_both_zero(i8 %a) {
71 ; CHECK-LABEL: @nonexact_ashr_ne_both_zero(
72 ; CHECK-NEXT: ret i1 false
75 %cmp = icmp ne i8 %shr, 0
79 define i1 @exact_lshr_eq_last_zero(i8 %a) {
80 ; CHECK-LABEL: @exact_lshr_eq_last_zero(
81 ; CHECK-NEXT: ret i1 false
83 %shr = lshr exact i8 128, %a
84 %cmp = icmp eq i8 %shr, 0
88 define i1 @exact_ashr_eq_last_zero(i8 %a) {
89 ; CHECK-LABEL: @exact_ashr_eq_last_zero(
90 ; CHECK-NEXT: ret i1 false
92 %shr = ashr exact i8 -128, %a
93 %cmp = icmp eq i8 %shr, 0
97 define i1 @nonexact_lshr_eq_both_zero(i8 %a) {
98 ; CHECK-LABEL: @nonexact_lshr_eq_both_zero(
99 ; CHECK-NEXT: ret i1 true
102 %cmp = icmp eq i8 %shr, 0
106 define i1 @exact_lshr_ne_last_zero(i8 %a) {
107 ; CHECK-LABEL: @exact_lshr_ne_last_zero(
108 ; CHECK-NEXT: ret i1 true
110 %shr = lshr exact i8 128, %a
111 %cmp = icmp ne i8 %shr, 0
115 define i1 @exact_ashr_ne_last_zero(i8 %a) {
116 ; CHECK-LABEL: @exact_ashr_ne_last_zero(
117 ; CHECK-NEXT: ret i1 true
119 %shr = ashr exact i8 -128, %a
120 %cmp = icmp ne i8 %shr, 0
124 define i1 @nonexact_lshr_eq_last_zero(i8 %a) {
125 ; CHECK-LABEL: @nonexact_lshr_eq_last_zero(
126 ; CHECK-NEXT: ret i1 false
128 %shr = lshr i8 128, %a
129 %cmp = icmp eq i8 %shr, 0
133 define i1 @nonexact_ashr_eq_last_zero(i8 %a) {
134 ; CHECK-LABEL: @nonexact_ashr_eq_last_zero(
135 ; CHECK-NEXT: ret i1 false
137 %shr = ashr i8 -128, %a
138 %cmp = icmp eq i8 %shr, 0
142 define i1 @nonexact_lshr_ne_last_zero(i8 %a) {
143 ; CHECK-LABEL: @nonexact_lshr_ne_last_zero(
144 ; CHECK-NEXT: ret i1 true
146 %shr = lshr i8 128, %a
147 %cmp = icmp ne i8 %shr, 0
151 define i1 @nonexact_ashr_ne_last_zero(i8 %a) {
152 ; CHECK-LABEL: @nonexact_ashr_ne_last_zero(
153 ; CHECK-NEXT: ret i1 true
155 %shr = ashr i8 -128, %a
156 %cmp = icmp ne i8 %shr, 0
160 define i1 @lshr_eq_first_zero(i8 %a) {
161 ; CHECK-LABEL: @lshr_eq_first_zero(
162 ; CHECK-NEXT: ret i1 false
165 %cmp = icmp eq i8 %shr, 2
169 define i1 @ashr_eq_first_zero(i8 %a) {
170 ; CHECK-LABEL: @ashr_eq_first_zero(
171 ; CHECK-NEXT: ret i1 false
174 %cmp = icmp eq i8 %shr, 2
178 define i1 @lshr_ne_first_zero(i8 %a) {
179 ; CHECK-LABEL: @lshr_ne_first_zero(
180 ; CHECK-NEXT: ret i1 true
183 %cmp = icmp ne i8 %shr, 2
187 define i1 @ashr_ne_first_zero(i8 %a) {
188 ; CHECK-LABEL: @ashr_ne_first_zero(
189 ; CHECK-NEXT: ret i1 true
192 %cmp = icmp ne i8 %shr, 2
196 define i1 @ashr_eq_both_minus1(i8 %a) {
197 ; CHECK-LABEL: @ashr_eq_both_minus1(
198 ; CHECK-NEXT: ret i1 true
200 %shr = ashr i8 -1, %a
201 %cmp = icmp eq i8 %shr, -1
205 define i1 @ashr_ne_both_minus1(i8 %a) {
206 ; CHECK-LABEL: @ashr_ne_both_minus1(
207 ; CHECK-NEXT: ret i1 false
209 %shr = ashr i8 -1, %a
210 %cmp = icmp ne i8 %shr, -1
214 define i1 @exact_ashr_eq_both_minus1(i8 %a) {
215 ; CHECK-LABEL: @exact_ashr_eq_both_minus1(
216 ; CHECK-NEXT: ret i1 true
218 %shr = ashr exact i8 -1, %a
219 %cmp = icmp eq i8 %shr, -1
223 define i1 @exact_ashr_ne_both_minus1(i8 %a) {
224 ; CHECK-LABEL: @exact_ashr_ne_both_minus1(
225 ; CHECK-NEXT: ret i1 false
227 %shr = ashr exact i8 -1, %a
228 %cmp = icmp ne i8 %shr, -1
232 define i1 @exact_ashr_eq_opposite_msb(i8 %a) {
233 ; CHECK-LABEL: @exact_ashr_eq_opposite_msb(
234 ; CHECK-NEXT: ret i1 false
236 %shr = ashr exact i8 -128, %a
237 %cmp = icmp eq i8 %shr, 1
241 define i1 @exact_ashr_eq_noexactlog(i8 %a) {
242 ; CHECK-LABEL: @exact_ashr_eq_noexactlog(
243 ; CHECK-NEXT: ret i1 false
245 %shr = ashr exact i8 -90, %a
246 %cmp = icmp eq i8 %shr, -30
250 define i1 @exact_ashr_ne_opposite_msb(i8 %a) {
251 ; CHECK-LABEL: @exact_ashr_ne_opposite_msb(
252 ; CHECK-NEXT: ret i1 true
254 %shr = ashr exact i8 -128, %a
255 %cmp = icmp ne i8 %shr, 1
259 define i1 @ashr_eq_opposite_msb(i8 %a) {
260 ; CHECK-LABEL: @ashr_eq_opposite_msb(
261 ; CHECK-NEXT: ret i1 false
263 %shr = ashr i8 -128, %a
264 %cmp = icmp eq i8 %shr, 1
268 define i1 @ashr_ne_opposite_msb(i8 %a) {
269 ; CHECK-LABEL: @ashr_ne_opposite_msb(
270 ; CHECK-NEXT: ret i1 true
272 %shr = ashr i8 -128, %a
273 %cmp = icmp ne i8 %shr, 1
277 define i1 @exact_ashr_eq_shift_gt(i8 %a) {
278 ; CHECK-LABEL: @exact_ashr_eq_shift_gt(
279 ; CHECK-NEXT: ret i1 false
281 %shr = ashr exact i8 -2, %a
282 %cmp = icmp eq i8 %shr, -8
286 define i1 @exact_ashr_ne_shift_gt(i8 %a) {
287 ; CHECK-LABEL: @exact_ashr_ne_shift_gt(
288 ; CHECK-NEXT: ret i1 true
290 %shr = ashr exact i8 -2, %a
291 %cmp = icmp ne i8 %shr, -8
295 define i1 @nonexact_ashr_eq_shift_gt(i8 %a) {
296 ; CHECK-LABEL: @nonexact_ashr_eq_shift_gt(
297 ; CHECK-NEXT: ret i1 false
299 %shr = ashr i8 -2, %a
300 %cmp = icmp eq i8 %shr, -8
304 define i1 @nonexact_ashr_ne_shift_gt(i8 %a) {
305 ; CHECK-LABEL: @nonexact_ashr_ne_shift_gt(
306 ; CHECK-NEXT: ret i1 true
308 %shr = ashr i8 -2, %a
309 %cmp = icmp ne i8 %shr, -8
313 define i1 @exact_lshr_eq_shift_gt(i8 %a) {
314 ; CHECK-LABEL: @exact_lshr_eq_shift_gt(
315 ; CHECK-NEXT: ret i1 false
317 %shr = lshr exact i8 2, %a
318 %cmp = icmp eq i8 %shr, 8
322 define i1 @exact_lshr_ne_shift_gt(i8 %a) {
323 ; CHECK-LABEL: @exact_lshr_ne_shift_gt(
324 ; CHECK-NEXT: ret i1 true
326 %shr = lshr exact i8 2, %a
327 %cmp = icmp ne i8 %shr, 8
331 define i1 @nonexact_lshr_eq_shift_gt(i8 %a) {
332 ; CHECK-LABEL: @nonexact_lshr_eq_shift_gt(
333 ; CHECK-NEXT: ret i1 false
336 %cmp = icmp eq i8 %shr, 8
340 define i1 @nonexact_lshr_ne_shift_gt(i8 %a) {
341 ; CHECK-LABEL: @nonexact_lshr_ne_shift_gt(
342 ; CHECK-NEXT: ret i1 true
345 %cmp = icmp ne i8 %shr, 8
349 define i1 @exact_ashr_ne_noexactlog(i8 %a) {
350 ; CHECK-LABEL: @exact_ashr_ne_noexactlog(
351 ; CHECK-NEXT: ret i1 true
353 %shr = ashr exact i8 -90, %a
354 %cmp = icmp ne i8 %shr, -30
358 define i1 @exact_lshr_eq_noexactlog(i8 %a) {
359 ; CHECK-LABEL: @exact_lshr_eq_noexactlog(
360 ; CHECK-NEXT: ret i1 false
362 %shr = lshr exact i8 90, %a
363 %cmp = icmp eq i8 %shr, 30
367 define i1 @exact_lshr_ne_noexactlog(i8 %a) {
368 ; CHECK-LABEL: @exact_lshr_ne_noexactlog(
369 ; CHECK-NEXT: ret i1 true
371 %shr = lshr exact i8 90, %a
372 %cmp = icmp ne i8 %shr, 30
376 define i32 @exact_lshr_lowbit(i32 %shiftval) {
377 ; CHECK-LABEL: @exact_lshr_lowbit(
378 ; CHECK-NEXT: ret i32 7
380 %shr = lshr exact i32 7, %shiftval
384 define i32 @exact_ashr_lowbit(i32 %shiftval) {
385 ; CHECK-LABEL: @exact_ashr_lowbit(
386 ; CHECK-NEXT: ret i32 7
388 %shr = ashr exact i32 7, %shiftval
392 define i32 @ashr_zero(i32 %shiftval) {
393 ; CHECK-LABEL: @ashr_zero(
394 ; CHECK-NEXT: ret i32 0
396 %shr = ashr i32 0, %shiftval
400 define i257 @ashr_minus1(i257 %shiftval) {
401 ; CHECK-LABEL: @ashr_minus1(
402 ; CHECK-NEXT: ret i257 -1
404 %shr = ashr i257 -1, %shiftval
408 define <2 x i4097> @ashr_zero_vec(<2 x i4097> %shiftval) {
409 ; CHECK-LABEL: @ashr_zero_vec(
410 ; CHECK-NEXT: ret <2 x i4097> zeroinitializer
412 %shr = ashr <2 x i4097> zeroinitializer, %shiftval
416 define <2 x i64> @ashr_minus1_vec(<2 x i64> %shiftval) {
417 ; CHECK-LABEL: @ashr_minus1_vec(
418 ; CHECK-NEXT: ret <2 x i64> <i64 -1, i64 -1>
420 %shr = ashr <2 x i64> <i64 -1, i64 -1>, %shiftval
424 define <2 x i4> @ashr_zero_minus1_vec(<2 x i4> %shiftval) {
425 ; CHECK-LABEL: @ashr_zero_minus1_vec(
426 ; CHECK-NEXT: ret <2 x i4> <i4 0, i4 -1>
428 %shr = ashr <2 x i4> <i4 0, i4 -1>, %shiftval