1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -instcombine < %s | FileCheck %s
5 define i32 @and_umax_less(i32 %A) {
6 ; CHECK-LABEL: @and_umax_less(
7 ; CHECK-NEXT: [[X:%.*]] = and i32 [[A:%.*]], -32
8 ; CHECK-NEXT: ret i32 [[X]]
10 %l0 = icmp ugt i32 31, %A
11 %l1 = select i1 %l0, i32 31, i32 %A
16 define i32 @and_umax_muchless(i32 %A) {
17 ; CHECK-LABEL: @and_umax_muchless(
18 ; CHECK-NEXT: [[X:%.*]] = and i32 [[A:%.*]], -32
19 ; CHECK-NEXT: ret i32 [[X]]
21 %l0 = icmp ugt i32 12, %A
22 %l1 = select i1 %l0, i32 12, i32 %A
27 define i32 @and_umax_more(i32 %A) {
28 ; CHECK-LABEL: @and_umax_more(
29 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[A:%.*]], 32
30 ; CHECK-NEXT: [[L1:%.*]] = select i1 [[TMP1]], i32 [[A]], i32 32
31 ; CHECK-NEXT: [[X:%.*]] = and i32 [[L1]], -32
32 ; CHECK-NEXT: ret i32 [[X]]
34 %l0 = icmp ugt i32 32, %A
35 %l1 = select i1 %l0, i32 32, i32 %A
40 define i32 @shr_umax(i32 %A) {
41 ; CHECK-LABEL: @shr_umax(
42 ; CHECK-NEXT: [[X:%.*]] = lshr i32 [[A:%.*]], 4
43 ; CHECK-NEXT: ret i32 [[X]]
45 %l0 = icmp ugt i32 15, %A
46 %l1 = select i1 %l0, i32 15, i32 %A
51 ; Various constants for C2 & umax(A, C1)
53 define i8 @t_0_1(i8 %A) {
54 ; CHECK-LABEL: @t_0_1(
55 ; CHECK-NEXT: [[X:%.*]] = and i8 [[A:%.*]], 1
56 ; CHECK-NEXT: ret i8 [[X]]
58 %l2 = icmp ugt i8 %A, 0
59 %l1 = select i1 %l2, i8 %A, i8 0
64 define i8 @t_0_10(i8 %A) {
65 ; CHECK-LABEL: @t_0_10(
66 ; CHECK-NEXT: [[X:%.*]] = and i8 [[A:%.*]], 10
67 ; CHECK-NEXT: ret i8 [[X]]
69 %l2 = icmp ugt i8 %A, 0
70 %l1 = select i1 %l2, i8 %A, i8 0
75 define i8 @t_1_10(i8 %A) {
76 ; CHECK-LABEL: @t_1_10(
77 ; CHECK-NEXT: [[X:%.*]] = and i8 [[A:%.*]], 10
78 ; CHECK-NEXT: ret i8 [[X]]
80 %l2 = icmp ugt i8 %A, 1
81 %l1 = select i1 %l2, i8 %A, i8 1
86 define i8 @t_2_4(i8 %A) {
87 ; CHECK-LABEL: @t_2_4(
88 ; CHECK-NEXT: [[X:%.*]] = and i8 [[A:%.*]], 4
89 ; CHECK-NEXT: ret i8 [[X]]
91 %l2 = icmp ugt i8 %A, 2
92 %l1 = select i1 %l2, i8 %A, i8 2
97 define i8 @t_2_192(i8 %A) {
98 ; CHECK-LABEL: @t_2_192(
99 ; CHECK-NEXT: [[X:%.*]] = and i8 [[A:%.*]], -64
100 ; CHECK-NEXT: ret i8 [[X]]
102 %l2 = icmp ugt i8 %A, 2
103 %l1 = select i1 %l2, i8 %A, i8 2
108 define i8 @t_2_63_or(i8 %A) {
109 ; CHECK-LABEL: @t_2_63_or(
110 ; CHECK-NEXT: [[X:%.*]] = or i8 [[A:%.*]], 63
111 ; CHECK-NEXT: ret i8 [[X]]
113 %l2 = icmp ugt i8 %A, 2
114 %l1 = select i1 %l2, i8 %A, i8 2
119 define i8 @f_1_1(i8 %A) {
120 ; CHECK-LABEL: @f_1_1(
121 ; CHECK-NEXT: [[L2:%.*]] = icmp ugt i8 [[A:%.*]], 1
122 ; CHECK-NEXT: [[L1:%.*]] = select i1 [[L2]], i8 [[A]], i8 1
123 ; CHECK-NEXT: [[X:%.*]] = and i8 [[L1]], 1
124 ; CHECK-NEXT: ret i8 [[X]]
126 %l2 = icmp ugt i8 %A, 1
127 %l1 = select i1 %l2, i8 %A, i8 1
132 define i8 @f_32_32(i8 %A) {
133 ; CHECK-LABEL: @f_32_32(
134 ; CHECK-NEXT: [[L2:%.*]] = icmp ugt i8 [[A:%.*]], 32
135 ; CHECK-NEXT: [[L1:%.*]] = select i1 [[L2]], i8 [[A]], i8 32
136 ; CHECK-NEXT: [[X:%.*]] = and i8 [[L1]], -32
137 ; CHECK-NEXT: ret i8 [[X]]
139 %l2 = icmp ugt i8 %A, 32
140 %l1 = select i1 %l2, i8 %A, i8 32
145 define i8 @f_191_192(i8 %A) {
146 ; CHECK-LABEL: @f_191_192(
147 ; CHECK-NEXT: [[L2:%.*]] = icmp ugt i8 [[A:%.*]], -65
148 ; CHECK-NEXT: [[L1:%.*]] = select i1 [[L2]], i8 [[A]], i8 -65
149 ; CHECK-NEXT: [[X:%.*]] = and i8 [[L1]], -64
150 ; CHECK-NEXT: ret i8 [[X]]
152 %l2 = icmp ugt i8 %A, 191
153 %l1 = select i1 %l2, i8 %A, i8 191
158 define i8 @f_10_1(i8 %A) {
159 ; CHECK-LABEL: @f_10_1(
160 ; CHECK-NEXT: [[L2:%.*]] = icmp ugt i8 [[A:%.*]], 10
161 ; CHECK-NEXT: [[L1:%.*]] = select i1 [[L2]], i8 [[A]], i8 10
162 ; CHECK-NEXT: [[X:%.*]] = and i8 [[L1]], 1
163 ; CHECK-NEXT: ret i8 [[X]]
165 %l2 = icmp ugt i8 %A, 10
166 %l1 = select i1 %l2, i8 %A, i8 10
171 define i32 @and_umin(i32 %A) {
172 ; CHECK-LABEL: @and_umin(
173 ; CHECK-NEXT: ret i32 0
175 %l0 = icmp ult i32 15, %A
176 %l1 = select i1 %l0, i32 15, i32 %A
177 %x = and i32 %l1, -32
181 define i32 @or_umin(i32 %A) {
182 ; CHECK-LABEL: @or_umin(
183 ; CHECK-NEXT: ret i32 31
185 %l0 = icmp ult i32 15, %A
186 %l1 = select i1 %l0, i32 15, i32 %A
191 define i8 @or_min_31_30(i8 %A) {
192 ; CHECK-LABEL: @or_min_31_30(
193 ; CHECK-NEXT: [[R:%.*]] = or i8 [[A:%.*]], 31
194 ; CHECK-NEXT: ret i8 [[R]]
196 %cmp = icmp ult i8 %A, -30
197 %min = select i1 %cmp, i8 %A, i8 -30
202 define i8 @and_min_7_7(i8 %A) {
203 ; CHECK-LABEL: @and_min_7_7(
204 ; CHECK-NEXT: [[R:%.*]] = and i8 [[A:%.*]], -8
205 ; CHECK-NEXT: ret i8 [[R]]
207 %l2 = icmp ult i8 %A, -7
208 %min = select i1 %l2, i8 %A, i8 -7
213 define i8 @and_min_7_8(i8 %A) {
214 ; CHECK-LABEL: @and_min_7_8(
215 ; CHECK-NEXT: [[R:%.*]] = and i8 [[A:%.*]], -8
216 ; CHECK-NEXT: ret i8 [[R]]
218 %l2 = icmp ult i8 %A, -8
219 %min = select i1 %l2, i8 %A, i8 -8
224 define i8 @and_min_7_9(i8 %A) {
225 ; CHECK-LABEL: @and_min_7_9(
226 ; CHECK-NEXT: [[L2:%.*]] = icmp ult i8 [[A:%.*]], -9
227 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[L2]], i8 [[A]], i8 -9
228 ; CHECK-NEXT: [[R:%.*]] = and i8 [[MIN]], -8
229 ; CHECK-NEXT: ret i8 [[R]]
231 %l2 = icmp ult i8 %A, -9
232 %min = select i1 %l2, i8 %A, i8 -9