1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=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: [[L1:%.*]] = call i32 @llvm.umax.i32(i32 [[A:%.*]], i32 32)
30 ; CHECK-NEXT: [[X:%.*]] = and i32 [[L1]], -32
31 ; CHECK-NEXT: ret i32 [[X]]
33 %l0 = icmp ugt i32 32, %A
34 %l1 = select i1 %l0, i32 32, i32 %A
39 define i32 @shr_umax(i32 %A) {
40 ; CHECK-LABEL: @shr_umax(
41 ; CHECK-NEXT: [[X:%.*]] = lshr i32 [[A:%.*]], 4
42 ; CHECK-NEXT: ret i32 [[X]]
44 %l0 = icmp ugt i32 15, %A
45 %l1 = select i1 %l0, i32 15, i32 %A
50 ; Various constants for C2 & umax(A, C1)
52 define i8 @t_0_1(i8 %A) {
53 ; CHECK-LABEL: @t_0_1(
54 ; CHECK-NEXT: [[X:%.*]] = and i8 [[A:%.*]], 1
55 ; CHECK-NEXT: ret i8 [[X]]
57 %l2 = icmp ugt i8 %A, 0
58 %l1 = select i1 %l2, i8 %A, i8 0
63 define i8 @t_0_10(i8 %A) {
64 ; CHECK-LABEL: @t_0_10(
65 ; CHECK-NEXT: [[X:%.*]] = and i8 [[A:%.*]], 10
66 ; CHECK-NEXT: ret i8 [[X]]
68 %l2 = icmp ugt i8 %A, 0
69 %l1 = select i1 %l2, i8 %A, i8 0
74 define i8 @t_1_10(i8 %A) {
75 ; CHECK-LABEL: @t_1_10(
76 ; CHECK-NEXT: [[X:%.*]] = and i8 [[A:%.*]], 10
77 ; CHECK-NEXT: ret i8 [[X]]
79 %l2 = icmp ugt i8 %A, 1
80 %l1 = select i1 %l2, i8 %A, i8 1
85 define i8 @t_2_4(i8 %A) {
86 ; CHECK-LABEL: @t_2_4(
87 ; CHECK-NEXT: [[X:%.*]] = and i8 [[A:%.*]], 4
88 ; CHECK-NEXT: ret i8 [[X]]
90 %l2 = icmp ugt i8 %A, 2
91 %l1 = select i1 %l2, i8 %A, i8 2
96 define i8 @t_2_192(i8 %A) {
97 ; CHECK-LABEL: @t_2_192(
98 ; CHECK-NEXT: [[X:%.*]] = and i8 [[A:%.*]], -64
99 ; CHECK-NEXT: ret i8 [[X]]
101 %l2 = icmp ugt i8 %A, 2
102 %l1 = select i1 %l2, i8 %A, i8 2
107 define i8 @t_2_63_or(i8 %A) {
108 ; CHECK-LABEL: @t_2_63_or(
109 ; CHECK-NEXT: [[X:%.*]] = or i8 [[A:%.*]], 63
110 ; CHECK-NEXT: ret i8 [[X]]
112 %l2 = icmp ugt i8 %A, 2
113 %l1 = select i1 %l2, i8 %A, i8 2
118 define i8 @f_1_1(i8 %A) {
119 ; CHECK-LABEL: @f_1_1(
120 ; CHECK-NEXT: [[L1:%.*]] = call i8 @llvm.umax.i8(i8 [[A:%.*]], i8 1)
121 ; CHECK-NEXT: [[X:%.*]] = and i8 [[L1]], 1
122 ; CHECK-NEXT: ret i8 [[X]]
124 %l2 = icmp ugt i8 %A, 1
125 %l1 = select i1 %l2, i8 %A, i8 1
130 define i8 @f_32_32(i8 %A) {
131 ; CHECK-LABEL: @f_32_32(
132 ; CHECK-NEXT: [[L1:%.*]] = call i8 @llvm.umax.i8(i8 [[A:%.*]], i8 32)
133 ; CHECK-NEXT: [[X:%.*]] = and i8 [[L1]], -32
134 ; CHECK-NEXT: ret i8 [[X]]
136 %l2 = icmp ugt i8 %A, 32
137 %l1 = select i1 %l2, i8 %A, i8 32
142 define i8 @f_191_192(i8 %A) {
143 ; CHECK-LABEL: @f_191_192(
144 ; CHECK-NEXT: [[L1:%.*]] = call i8 @llvm.umax.i8(i8 [[A:%.*]], i8 -65)
145 ; CHECK-NEXT: [[X:%.*]] = and i8 [[L1]], -64
146 ; CHECK-NEXT: ret i8 [[X]]
148 %l2 = icmp ugt i8 %A, 191
149 %l1 = select i1 %l2, i8 %A, i8 191
154 define i8 @f_10_1(i8 %A) {
155 ; CHECK-LABEL: @f_10_1(
156 ; CHECK-NEXT: [[L1:%.*]] = call i8 @llvm.umax.i8(i8 [[A:%.*]], i8 10)
157 ; CHECK-NEXT: [[X:%.*]] = and i8 [[L1]], 1
158 ; CHECK-NEXT: ret i8 [[X]]
160 %l2 = icmp ugt i8 %A, 10
161 %l1 = select i1 %l2, i8 %A, i8 10
166 define i32 @and_umin(i32 %A) {
167 ; CHECK-LABEL: @and_umin(
168 ; CHECK-NEXT: ret i32 0
170 %l0 = icmp ult i32 15, %A
171 %l1 = select i1 %l0, i32 15, i32 %A
172 %x = and i32 %l1, -32
176 define i32 @or_umin(i32 %A) {
177 ; CHECK-LABEL: @or_umin(
178 ; CHECK-NEXT: ret i32 31
180 %l0 = icmp ult i32 15, %A
181 %l1 = select i1 %l0, i32 15, i32 %A
186 define i8 @or_min_31_30(i8 %A) {
187 ; CHECK-LABEL: @or_min_31_30(
188 ; CHECK-NEXT: [[R:%.*]] = or i8 [[A:%.*]], 31
189 ; CHECK-NEXT: ret i8 [[R]]
191 %cmp = icmp ult i8 %A, -30
192 %min = select i1 %cmp, i8 %A, i8 -30
197 define i8 @and_min_7_7(i8 %A) {
198 ; CHECK-LABEL: @and_min_7_7(
199 ; CHECK-NEXT: [[R:%.*]] = and i8 [[A:%.*]], -8
200 ; CHECK-NEXT: ret i8 [[R]]
202 %l2 = icmp ult i8 %A, -7
203 %min = select i1 %l2, i8 %A, i8 -7
208 define i8 @and_min_7_8(i8 %A) {
209 ; CHECK-LABEL: @and_min_7_8(
210 ; CHECK-NEXT: [[R:%.*]] = and i8 [[A:%.*]], -8
211 ; CHECK-NEXT: ret i8 [[R]]
213 %l2 = icmp ult i8 %A, -8
214 %min = select i1 %l2, i8 %A, i8 -8
219 define i8 @and_min_7_9(i8 %A) {
220 ; CHECK-LABEL: @and_min_7_9(
221 ; CHECK-NEXT: [[MIN:%.*]] = call i8 @llvm.umin.i8(i8 [[A:%.*]], i8 -9)
222 ; CHECK-NEXT: [[R:%.*]] = and i8 [[MIN]], -8
223 ; CHECK-NEXT: ret i8 [[R]]
225 %l2 = icmp ult i8 %A, -9
226 %min = select i1 %l2, i8 %A, i8 -9