1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
6 define i1 @set_low_bit_mask_eq(i8 %x) {
7 ; CHECK-LABEL: @set_low_bit_mask_eq(
8 ; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], -2
9 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[TMP1]], 18
10 ; CHECK-NEXT: ret i1 [[CMP]]
13 %cmp = icmp eq i8 %sub, 19
17 define <2 x i1> @set_low_bit_mask_ne(<2 x i8> %x) {
18 ; CHECK-LABEL: @set_low_bit_mask_ne(
19 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[X:%.*]], <i8 -4, i8 -4>
20 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i8> [[TMP1]], <i8 16, i8 16>
21 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
23 %sub = or <2 x i8> %x, <i8 3, i8 3>
24 %cmp = icmp ne <2 x i8> %sub, <i8 19, i8 19>
28 define i1 @set_low_bit_mask_ugt(i8 %x) {
29 ; CHECK-LABEL: @set_low_bit_mask_ugt(
30 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X:%.*]], 19
31 ; CHECK-NEXT: ret i1 [[CMP]]
34 %cmp = icmp ugt i8 %sub, 19
38 define i1 @set_low_bit_mask_ult(i8 %x) {
39 ; CHECK-LABEL: @set_low_bit_mask_ult(
40 ; CHECK-NEXT: [[SUB:%.*]] = or i8 [[X:%.*]], 3
41 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[SUB]], 19
42 ; CHECK-NEXT: ret i1 [[CMP]]
45 %cmp = icmp ult i8 %sub, 19
49 define i1 @set_low_bit_mask_uge(i8 %x) {
50 ; CHECK-LABEL: @set_low_bit_mask_uge(
51 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X:%.*]], 19
52 ; CHECK-NEXT: ret i1 [[CMP]]
55 %cmp = icmp uge i8 %sub, 20
59 define i1 @set_low_bit_mask_ule(i8 %x) {
60 ; CHECK-LABEL: @set_low_bit_mask_ule(
61 ; CHECK-NEXT: [[SUB:%.*]] = or i8 [[X:%.*]], 3
62 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[SUB]], 19
63 ; CHECK-NEXT: ret i1 [[CMP]]
66 %cmp = icmp ule i8 %sub, 18
70 define i1 @set_low_bit_mask_sgt(i8 %x) {
71 ; CHECK-LABEL: @set_low_bit_mask_sgt(
72 ; CHECK-NEXT: [[SUB:%.*]] = or i8 [[X:%.*]], 3
73 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[SUB]], 20
74 ; CHECK-NEXT: ret i1 [[CMP]]
77 %cmp = icmp sgt i8 %sub, 20
81 define i1 @set_low_bit_mask_slt(i8 %x) {
82 ; CHECK-LABEL: @set_low_bit_mask_slt(
83 ; CHECK-NEXT: [[SUB:%.*]] = or i8 [[X:%.*]], 15
84 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[SUB]], 19
85 ; CHECK-NEXT: ret i1 [[CMP]]
88 %cmp = icmp slt i8 %sub, 19
92 define i1 @set_low_bit_mask_sge(i8 %x) {
93 ; CHECK-LABEL: @set_low_bit_mask_sge(
94 ; CHECK-NEXT: [[SUB:%.*]] = or i8 [[X:%.*]], 31
95 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[SUB]], 50
96 ; CHECK-NEXT: ret i1 [[CMP]]
99 %cmp = icmp sge i8 %sub, 51
103 define i1 @set_low_bit_mask_sle(i8 %x) {
104 ; CHECK-LABEL: @set_low_bit_mask_sle(
105 ; CHECK-NEXT: [[SUB:%.*]] = or i8 [[X:%.*]], 63
106 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[SUB]], 69
107 ; CHECK-NEXT: ret i1 [[CMP]]
110 %cmp = icmp sle i8 %sub, 68
114 define i1 @eq_const_mask(i8 %x, i8 %y) {
115 ; CHECK-LABEL: @eq_const_mask(
116 ; CHECK-NEXT: [[TMP1:%.*]] = xor i8 [[X:%.*]], [[Y:%.*]]
117 ; CHECK-NEXT: [[TMP2:%.*]] = and i8 [[TMP1]], -43
118 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[TMP2]], 0
119 ; CHECK-NEXT: ret i1 [[CMP]]
123 %cmp = icmp eq i8 %b0, %b1
127 define <2 x i1> @ne_const_mask(<2 x i8> %x, <2 x i8> %y) {
128 ; CHECK-LABEL: @ne_const_mask(
129 ; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i8> [[X:%.*]], [[Y:%.*]]
130 ; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i8> [[TMP1]], <i8 105, i8 -6>
131 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i8> [[TMP2]], zeroinitializer
132 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
134 %b0 = or <2 x i8> %x, <i8 150, i8 5>
135 %b1 = or <2 x i8> %y, <i8 150, i8 5>
136 %cmp = icmp ne <2 x i8> %b0, %b1
140 ; negative test - predicate
142 define i1 @eq_const_mask_not_equality(i8 %x, i8 %y) {
143 ; CHECK-LABEL: @eq_const_mask_not_equality(
144 ; CHECK-NEXT: [[B0:%.*]] = or i8 [[X:%.*]], 5
145 ; CHECK-NEXT: [[B1:%.*]] = or i8 [[Y:%.*]], 5
146 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[B0]], [[B1]]
147 ; CHECK-NEXT: ret i1 [[CMP]]
151 %cmp = icmp sgt i8 %b0, %b1
155 ; negative test - mismatched constants
157 define i1 @eq_const_mask_not_same(i8 %x, i8 %y) {
158 ; CHECK-LABEL: @eq_const_mask_not_same(
159 ; CHECK-NEXT: [[B0:%.*]] = or i8 [[X:%.*]], 5
160 ; CHECK-NEXT: [[B1:%.*]] = or i8 [[Y:%.*]], 6
161 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[B0]], [[B1]]
162 ; CHECK-NEXT: ret i1 [[CMP]]
166 %cmp = icmp eq i8 %b0, %b1
170 ; negative test - mismatched logic
172 define i1 @eq_const_mask_wrong_opcode(i8 %x, i8 %y) {
173 ; CHECK-LABEL: @eq_const_mask_wrong_opcode(
174 ; CHECK-NEXT: [[B0:%.*]] = or i8 [[X:%.*]], 5
175 ; CHECK-NEXT: [[B1:%.*]] = xor i8 [[Y:%.*]], 5
176 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[B0]], [[B1]]
177 ; CHECK-NEXT: ret i1 [[CMP]]
181 %cmp = icmp eq i8 %b0, %b1
185 ; negative test - no extra uses
187 define i1 @eq_const_mask_use1(i8 %x, i8 %y) {
188 ; CHECK-LABEL: @eq_const_mask_use1(
189 ; CHECK-NEXT: [[B0:%.*]] = or i8 [[X:%.*]], 5
190 ; CHECK-NEXT: call void @use(i8 [[B0]])
191 ; CHECK-NEXT: [[B1:%.*]] = or i8 [[Y:%.*]], 5
192 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[B0]], [[B1]]
193 ; CHECK-NEXT: ret i1 [[CMP]]
196 call void @use(i8 %b0)
198 %cmp = icmp eq i8 %b0, %b1
202 ; negative test - no extra uses
204 define i1 @eq_const_mask_use2(i8 %x, i8 %y) {
205 ; CHECK-LABEL: @eq_const_mask_use2(
206 ; CHECK-NEXT: [[B0:%.*]] = or i8 [[X:%.*]], 5
207 ; CHECK-NEXT: [[B1:%.*]] = or i8 [[Y:%.*]], 5
208 ; CHECK-NEXT: call void @use(i8 [[B1]])
209 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[B0]], [[B1]]
210 ; CHECK-NEXT: ret i1 [[CMP]]
214 call void @use(i8 %b1)
215 %cmp = icmp eq i8 %b0, %b1
221 define <2 x i1> @decrement_slt_0(<2 x i8> %x) {
222 ; CHECK-LABEL: @decrement_slt_0(
223 ; CHECK-NEXT: [[R:%.*]] = icmp slt <2 x i8> [[X:%.*]], <i8 1, i8 1>
224 ; CHECK-NEXT: ret <2 x i1> [[R]]
226 %dec = add <2 x i8> %x, <i8 -1, i8 -1>
227 %or = or <2 x i8> %dec, %x
228 %r = icmp slt <2 x i8> %or, zeroinitializer
232 define i1 @decrement_slt_0_commute_use1(i8 %px) {
233 ; CHECK-LABEL: @decrement_slt_0_commute_use1(
234 ; CHECK-NEXT: [[X:%.*]] = mul i8 [[PX:%.*]], 42
235 ; CHECK-NEXT: [[DEC:%.*]] = add i8 [[X]], -1
236 ; CHECK-NEXT: call void @use(i8 [[DEC]])
237 ; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[X]], 1
238 ; CHECK-NEXT: ret i1 [[R]]
240 %x = mul i8 %px, 42 ; thwart complexity-based canonicalization
242 call void @use(i8 %dec)
244 %r = icmp slt i8 %or, 0
248 define i1 @decrement_slt_0_use2(i8 %x) {
249 ; CHECK-LABEL: @decrement_slt_0_use2(
250 ; CHECK-NEXT: [[DEC:%.*]] = add i8 [[X:%.*]], -1
251 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[DEC]], [[X]]
252 ; CHECK-NEXT: call void @use(i8 [[OR]])
253 ; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[X]], 1
254 ; CHECK-NEXT: ret i1 [[R]]
258 call void @use(i8 %or)
259 %r = icmp slt i8 %or, 0
263 ; negative test - wrong cmp constant
265 define i1 @decrement_slt_n1(i8 %x) {
266 ; CHECK-LABEL: @decrement_slt_n1(
267 ; CHECK-NEXT: [[DEC:%.*]] = add i8 [[X:%.*]], -1
268 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[DEC]], [[X]]
269 ; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[OR]], -1
270 ; CHECK-NEXT: ret i1 [[R]]
274 %r = icmp slt i8 %or, -1
278 ; negative test - wrong add constant
280 define i1 @not_decrement_slt_0(i8 %x) {
281 ; CHECK-LABEL: @not_decrement_slt_0(
282 ; CHECK-NEXT: [[DEC:%.*]] = add i8 [[X:%.*]], -2
283 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[DEC]], [[X]]
284 ; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[OR]], 0
285 ; CHECK-NEXT: ret i1 [[R]]
289 %r = icmp slt i8 %or, 0
293 ; (x | (x - 1)) s> -1
295 define <2 x i1> @decrement_sgt_n1(<2 x i8> %x) {
296 ; CHECK-LABEL: @decrement_sgt_n1(
297 ; CHECK-NEXT: [[R:%.*]] = icmp sgt <2 x i8> [[X:%.*]], zeroinitializer
298 ; CHECK-NEXT: ret <2 x i1> [[R]]
300 %dec = add <2 x i8> %x, <i8 -1, i8 -1>
301 %or = or <2 x i8> %dec, %x
302 %r = icmp sgt <2 x i8> %or, <i8 -1, i8 -1>
306 define i1 @decrement_sgt_n1_commute_use1(i8 %px) {
307 ; CHECK-LABEL: @decrement_sgt_n1_commute_use1(
308 ; CHECK-NEXT: [[X:%.*]] = mul i8 [[PX:%.*]], 42
309 ; CHECK-NEXT: [[DEC:%.*]] = add i8 [[X]], -1
310 ; CHECK-NEXT: call void @use(i8 [[DEC]])
311 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[X]], 0
312 ; CHECK-NEXT: ret i1 [[R]]
314 %x = mul i8 %px, 42 ; thwart complexity-based canonicalization
316 call void @use(i8 %dec)
318 %r = icmp sgt i8 %or, -1
322 define i1 @decrement_sgt_n1_use2(i8 %x) {
323 ; CHECK-LABEL: @decrement_sgt_n1_use2(
324 ; CHECK-NEXT: [[DEC:%.*]] = add i8 [[X:%.*]], -1
325 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[DEC]], [[X]]
326 ; CHECK-NEXT: call void @use(i8 [[OR]])
327 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[X]], 0
328 ; CHECK-NEXT: ret i1 [[R]]
332 call void @use(i8 %or)
333 %r = icmp sgt i8 %or, -1
337 ; negative test - wrong cmp constant
339 define i1 @decrement_sgt_0(i8 %x) {
340 ; CHECK-LABEL: @decrement_sgt_0(
341 ; CHECK-NEXT: [[DEC:%.*]] = add i8 [[X:%.*]], -1
342 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[DEC]], [[X]]
343 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[OR]], 0
344 ; CHECK-NEXT: ret i1 [[R]]
348 %r = icmp sgt i8 %or, 0
352 ; negative test - wrong add constant
354 define i1 @not_decrement_sgt_n1(i8 %x) {
355 ; CHECK-LABEL: @not_decrement_sgt_n1(
356 ; CHECK-NEXT: [[DEC:%.*]] = add i8 [[X:%.*]], -2
357 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[DEC]], [[X]]
358 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[OR]], -1
359 ; CHECK-NEXT: ret i1 [[R]]
363 %r = icmp sgt i8 %or, -1