1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 define i8 @shl_add_nuw(i8 %amt_in, i8 %cnt_in) {
5 ; CHECK-LABEL: @shl_add_nuw(
6 ; CHECK-NEXT: [[AMT:%.*]] = and i8 [[AMT_IN:%.*]], 63
7 ; CHECK-NEXT: [[CNT:%.*]] = and i8 [[CNT_IN:%.*]], 2
8 ; CHECK-NEXT: [[R:%.*]] = shl nuw i8 [[AMT]], [[CNT]]
9 ; CHECK-NEXT: ret i8 [[R]]
11 %amt = and i8 %amt_in, 63
12 %cnt = and i8 %cnt_in, 2
13 %r = shl i8 %amt, %cnt
17 define i8 @shl_add_nuw_fail(i8 %amt_in, i8 %cnt_in) {
18 ; CHECK-LABEL: @shl_add_nuw_fail(
19 ; CHECK-NEXT: [[AMT:%.*]] = and i8 [[AMT_IN:%.*]], 63
20 ; CHECK-NEXT: [[CNT:%.*]] = and i8 [[CNT_IN:%.*]], 3
21 ; CHECK-NEXT: [[R:%.*]] = shl i8 [[AMT]], [[CNT]]
22 ; CHECK-NEXT: ret i8 [[R]]
24 %amt = and i8 %amt_in, 63
25 %cnt = and i8 %cnt_in, 3
26 %r = shl i8 %amt, %cnt
30 define i8 @shl_add_nuw_and_nsw(i8 %amt_in, i8 %cnt_in) {
31 ; CHECK-LABEL: @shl_add_nuw_and_nsw(
32 ; CHECK-NEXT: [[AMT:%.*]] = and i8 [[AMT_IN:%.*]], 31
33 ; CHECK-NEXT: [[CNT:%.*]] = and i8 [[CNT_IN:%.*]], 2
34 ; CHECK-NEXT: [[R:%.*]] = shl nuw nsw i8 [[AMT]], [[CNT]]
35 ; CHECK-NEXT: ret i8 [[R]]
37 %amt = and i8 %amt_in, 31
38 %cnt = and i8 %cnt_in, 2
39 %r = shl i8 %amt, %cnt
43 define i8 @shl_add_nsw(i8 %amt_in, i8 %cnt_in) {
44 ; CHECK-LABEL: @shl_add_nsw(
45 ; CHECK-NEXT: [[AMT:%.*]] = or i8 [[AMT_IN:%.*]], -32
46 ; CHECK-NEXT: [[CNT:%.*]] = and i8 [[CNT_IN:%.*]], 2
47 ; CHECK-NEXT: [[R:%.*]] = shl nsw i8 [[AMT]], [[CNT]]
48 ; CHECK-NEXT: ret i8 [[R]]
50 %amt = or i8 %amt_in, 224
51 %cnt = and i8 %cnt_in, 2
52 %r = shl i8 %amt, %cnt
56 define i8 @shl_add_nsw_fail(i8 %amt_in, i8 %cnt_in) {
57 ; CHECK-LABEL: @shl_add_nsw_fail(
58 ; CHECK-NEXT: [[AMT:%.*]] = or i8 [[AMT_IN:%.*]], -64
59 ; CHECK-NEXT: [[CNT:%.*]] = and i8 [[CNT_IN:%.*]], 2
60 ; CHECK-NEXT: [[R:%.*]] = shl i8 [[AMT]], [[CNT]]
61 ; CHECK-NEXT: ret i8 [[R]]
63 %amt = or i8 %amt_in, 192
64 %cnt = and i8 %cnt_in, 2
65 %r = shl i8 %amt, %cnt
69 define i8 @lshr_add_exact(i8 %amt_in, i8 %cnt_in) {
70 ; CHECK-LABEL: @lshr_add_exact(
71 ; CHECK-NEXT: [[AMT:%.*]] = and i8 [[AMT_IN:%.*]], -4
72 ; CHECK-NEXT: [[CNT:%.*]] = and i8 [[CNT_IN:%.*]], 2
73 ; CHECK-NEXT: [[R:%.*]] = lshr exact i8 [[AMT]], [[CNT]]
74 ; CHECK-NEXT: ret i8 [[R]]
76 %amt = and i8 %amt_in, -4
77 %cnt = and i8 %cnt_in, 2
78 %r = lshr i8 %amt, %cnt
82 define i8 @lshr_add_exact_fail(i8 %amt_in, i8 %cnt_in) {
83 ; CHECK-LABEL: @lshr_add_exact_fail(
84 ; CHECK-NEXT: [[AMT:%.*]] = and i8 [[AMT_IN:%.*]], -7
85 ; CHECK-NEXT: [[CNT:%.*]] = and i8 [[CNT_IN:%.*]], 2
86 ; CHECK-NEXT: [[R:%.*]] = lshr i8 [[AMT]], [[CNT]]
87 ; CHECK-NEXT: ret i8 [[R]]
89 %amt = and i8 %amt_in, -7
90 %cnt = and i8 %cnt_in, 2
91 %r = lshr i8 %amt, %cnt
95 define i8 @ashr_add_exact(i8 %amt_in, i8 %cnt_in) {
96 ; CHECK-LABEL: @ashr_add_exact(
97 ; CHECK-NEXT: [[AMT:%.*]] = and i8 [[AMT_IN:%.*]], -14
98 ; CHECK-NEXT: [[CNT:%.*]] = and i8 [[CNT_IN:%.*]], 1
99 ; CHECK-NEXT: [[R:%.*]] = ashr exact i8 [[AMT]], [[CNT]]
100 ; CHECK-NEXT: ret i8 [[R]]
102 %amt = and i8 %amt_in, -14
103 %cnt = and i8 %cnt_in, 1
104 %r = ashr i8 %amt, %cnt
108 define i8 @ashr_add_exact_fail(i8 %amt_in, i8 %cnt_in) {
109 ; CHECK-LABEL: @ashr_add_exact_fail(
110 ; CHECK-NEXT: [[AMT:%.*]] = and i8 [[AMT_IN:%.*]], -14
111 ; CHECK-NEXT: [[CNT:%.*]] = and i8 [[CNT_IN:%.*]], 2
112 ; CHECK-NEXT: [[R:%.*]] = ashr i8 [[AMT]], [[CNT]]
113 ; CHECK-NEXT: ret i8 [[R]]
115 %amt = and i8 %amt_in, -14
116 %cnt = and i8 %cnt_in, 2
117 %r = ashr i8 %amt, %cnt