Skip to content

Commit 67ba293

Browse files
committed
[InstCombine] Add tests for transforming (icmp pred (and X, Y), X); NFC
Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D145424
1 parent 377497f commit 67ba293

File tree

1 file changed

+300
-0
lines changed

1 file changed

+300
-0
lines changed
Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3+
4+
declare i1 @barrier()
5+
declare void @llvm.assume(i1)
6+
7+
define i1 @icmp_ult_x_y(i8 %x, i8 %y) {
8+
; CHECK-LABEL: @icmp_ult_x_y(
9+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], [[Y:%.*]]
10+
; CHECK-NEXT: [[Z:%.*]] = icmp ult i8 [[AND]], [[X]]
11+
; CHECK-NEXT: ret i1 [[Z]]
12+
;
13+
%and = and i8 %x, %y
14+
%z = icmp ult i8 %and, %x
15+
ret i1 %z
16+
}
17+
18+
define i1 @icmp_ult_x_y_2(i8 %xx, i8 %y) {
19+
; CHECK-LABEL: @icmp_ult_x_y_2(
20+
; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], [[XX]]
21+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], [[Y:%.*]]
22+
; CHECK-NEXT: [[Z:%.*]] = icmp ugt i8 [[X]], [[AND]]
23+
; CHECK-NEXT: ret i1 [[Z]]
24+
;
25+
%x = mul i8 %xx, %xx
26+
%and = and i8 %x, %y
27+
%z = icmp ugt i8 %x, %and
28+
ret i1 %z
29+
}
30+
31+
define <2 x i1> @icmp_uge_x_y(<2 x i8> %x, <2 x i8> %y) {
32+
; CHECK-LABEL: @icmp_uge_x_y(
33+
; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[X:%.*]], [[Y:%.*]]
34+
; CHECK-NEXT: [[Z:%.*]] = icmp uge <2 x i8> [[AND]], [[X]]
35+
; CHECK-NEXT: ret <2 x i1> [[Z]]
36+
;
37+
%and = and <2 x i8> %x, %y
38+
%z = icmp uge <2 x i8> %and, %x
39+
ret <2 x i1> %z
40+
}
41+
42+
define i1 @icmp_uge_x_y_2(i8 %xx, i8 %y) {
43+
; CHECK-LABEL: @icmp_uge_x_y_2(
44+
; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], [[XX]]
45+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], [[Y:%.*]]
46+
; CHECK-NEXT: [[Z:%.*]] = icmp ule i8 [[X]], [[AND]]
47+
; CHECK-NEXT: ret i1 [[Z]]
48+
;
49+
%x = mul i8 %xx, %xx
50+
%and = and i8 %x, %y
51+
%z = icmp ule i8 %x, %and
52+
ret i1 %z
53+
}
54+
55+
define i1 @icmp_sge_x_negy(i8 %x, i8 %y) {
56+
; CHECK-LABEL: @icmp_sge_x_negy(
57+
; CHECK-NEXT: [[CY:%.*]] = icmp slt i8 [[Y:%.*]], 0
58+
; CHECK-NEXT: call void @llvm.assume(i1 [[CY]])
59+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], [[Y]]
60+
; CHECK-NEXT: [[Z:%.*]] = icmp sge i8 [[AND]], [[X]]
61+
; CHECK-NEXT: ret i1 [[Z]]
62+
;
63+
%cy = icmp slt i8 %y, 0
64+
call void @llvm.assume(i1 %cy)
65+
%and = and i8 %x, %y
66+
%z = icmp sge i8 %and, %x
67+
ret i1 %z
68+
}
69+
70+
define i1 @icmp_slt_x_negy(i8 %x, i8 %y) {
71+
; CHECK-LABEL: @icmp_slt_x_negy(
72+
; CHECK-NEXT: [[CY:%.*]] = icmp slt i8 [[Y:%.*]], 0
73+
; CHECK-NEXT: br i1 [[CY]], label [[NEGY:%.*]], label [[POSY:%.*]]
74+
; CHECK: negy:
75+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], [[Y]]
76+
; CHECK-NEXT: [[Z:%.*]] = icmp slt i8 [[AND]], [[X]]
77+
; CHECK-NEXT: ret i1 [[Z]]
78+
; CHECK: posy:
79+
; CHECK-NEXT: [[R:%.*]] = call i1 @barrier()
80+
; CHECK-NEXT: ret i1 [[R]]
81+
;
82+
%cy = icmp slt i8 %y, 0
83+
br i1 %cy, label %negy, label %posy
84+
negy:
85+
%and = and i8 %x, %y
86+
%z = icmp slt i8 %and, %x
87+
ret i1 %z
88+
posy:
89+
%r = call i1 @barrier()
90+
ret i1 %r
91+
}
92+
93+
define i1 @icmp_slt_x_negy_fail_maybe_zero(i8 %x, i8 %y) {
94+
; CHECK-LABEL: @icmp_slt_x_negy_fail_maybe_zero(
95+
; CHECK-NEXT: [[CY:%.*]] = icmp slt i8 [[Y:%.*]], 1
96+
; CHECK-NEXT: br i1 [[CY]], label [[NEGY:%.*]], label [[POSY:%.*]]
97+
; CHECK: negy:
98+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], [[Y]]
99+
; CHECK-NEXT: [[Z:%.*]] = icmp slt i8 [[AND]], [[X]]
100+
; CHECK-NEXT: ret i1 [[Z]]
101+
; CHECK: posy:
102+
; CHECK-NEXT: [[R:%.*]] = call i1 @barrier()
103+
; CHECK-NEXT: ret i1 [[R]]
104+
;
105+
%cy = icmp sle i8 %y, 0
106+
br i1 %cy, label %negy, label %posy
107+
negy:
108+
%and = and i8 %x, %y
109+
%z = icmp slt i8 %and, %x
110+
ret i1 %z
111+
posy:
112+
%r = call i1 @barrier()
113+
ret i1 %r
114+
}
115+
116+
define i1 @icmp_sle_x_negy(i8 %x, i8 %yy) {
117+
; CHECK-LABEL: @icmp_sle_x_negy(
118+
; CHECK-NEXT: [[Y:%.*]] = or i8 [[YY:%.*]], -128
119+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[Y]], [[X:%.*]]
120+
; CHECK-NEXT: [[Z:%.*]] = icmp sle i8 [[AND]], [[X]]
121+
; CHECK-NEXT: ret i1 [[Z]]
122+
;
123+
%y = or i8 %yy, 128
124+
%and = and i8 %y, %x
125+
%z = icmp sle i8 %and, %x
126+
ret i1 %z
127+
}
128+
129+
define <2 x i1> @icmp_sgt_x_negy(<2 x i8> %x, <2 x i8> %yy) {
130+
; CHECK-LABEL: @icmp_sgt_x_negy(
131+
; CHECK-NEXT: [[Y:%.*]] = or <2 x i8> [[YY:%.*]], <i8 -128, i8 -128>
132+
; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[Y]], [[X:%.*]]
133+
; CHECK-NEXT: [[Z:%.*]] = icmp sgt <2 x i8> [[AND]], [[X]]
134+
; CHECK-NEXT: ret <2 x i1> [[Z]]
135+
;
136+
%y = or <2 x i8> %yy, <i8 128, i8 128>
137+
%and = and <2 x i8> %y, %x
138+
%z = icmp sgt <2 x i8> %and, %x
139+
ret <2 x i1> %z
140+
}
141+
142+
define <2 x i1> @icmp_sgt_x_negy_fail_partial(<2 x i8> %x, <2 x i8> %yy) {
143+
; CHECK-LABEL: @icmp_sgt_x_negy_fail_partial(
144+
; CHECK-NEXT: [[Y:%.*]] = or <2 x i8> [[YY:%.*]], <i8 -128, i8 4>
145+
; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[Y]], [[X:%.*]]
146+
; CHECK-NEXT: [[Z:%.*]] = icmp sgt <2 x i8> [[AND]], [[X]]
147+
; CHECK-NEXT: ret <2 x i1> [[Z]]
148+
;
149+
%y = or <2 x i8> %yy, <i8 128, i8 4>
150+
%and = and <2 x i8> %y, %x
151+
%z = icmp sgt <2 x i8> %and, %x
152+
ret <2 x i1> %z
153+
}
154+
155+
define <2 x i1> @icmp_sle_x_posy(<2 x i8> %x, <2 x i8> %yy) {
156+
; CHECK-LABEL: @icmp_sle_x_posy(
157+
; CHECK-NEXT: [[Y:%.*]] = and <2 x i8> [[YY:%.*]], <i8 127, i8 127>
158+
; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[Y]], [[X:%.*]]
159+
; CHECK-NEXT: [[Z:%.*]] = icmp sle <2 x i8> [[AND]], [[X]]
160+
; CHECK-NEXT: ret <2 x i1> [[Z]]
161+
;
162+
%y = and <2 x i8> %yy, <i8 127, i8 127>
163+
%and = and <2 x i8> %y, %x
164+
%z = icmp sle <2 x i8> %and, %x
165+
ret <2 x i1> %z
166+
}
167+
168+
define <2 x i1> @icmp_sle_x_posy_fail_partial(<2 x i8> %x, <2 x i8> %yy) {
169+
; CHECK-LABEL: @icmp_sle_x_posy_fail_partial(
170+
; CHECK-NEXT: [[Y:%.*]] = and <2 x i8> [[YY:%.*]], <i8 127, i8 -65>
171+
; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[Y]], [[X:%.*]]
172+
; CHECK-NEXT: [[Z:%.*]] = icmp sle <2 x i8> [[AND]], [[X]]
173+
; CHECK-NEXT: ret <2 x i1> [[Z]]
174+
;
175+
%y = and <2 x i8> %yy, <i8 127, i8 191>
176+
%and = and <2 x i8> %y, %x
177+
%z = icmp sle <2 x i8> %and, %x
178+
ret <2 x i1> %z
179+
}
180+
181+
define i1 @icmp_sgt_x_posy(i8 %x, i8 %y) {
182+
; CHECK-LABEL: @icmp_sgt_x_posy(
183+
; CHECK-NEXT: [[CY:%.*]] = icmp sgt i8 [[Y:%.*]], -1
184+
; CHECK-NEXT: call void @llvm.assume(i1 [[CY]])
185+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], [[Y]]
186+
; CHECK-NEXT: [[Z:%.*]] = icmp sgt i8 [[AND]], [[X]]
187+
; CHECK-NEXT: ret i1 [[Z]]
188+
;
189+
%cy = icmp sge i8 %y, 0
190+
call void @llvm.assume(i1 %cy)
191+
%and = and i8 %x, %y
192+
%z = icmp sgt i8 %and, %x
193+
ret i1 %z
194+
}
195+
196+
define <2 x i1> @icmp_sgt_negx_y(<2 x i8> %xx, <2 x i8> %y) {
197+
; CHECK-LABEL: @icmp_sgt_negx_y(
198+
; CHECK-NEXT: [[X:%.*]] = or <2 x i8> [[XX:%.*]], <i8 -128, i8 -128>
199+
; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[X]], [[Y:%.*]]
200+
; CHECK-NEXT: [[Z:%.*]] = icmp sgt <2 x i8> [[AND]], [[X]]
201+
; CHECK-NEXT: ret <2 x i1> [[Z]]
202+
;
203+
%x = or <2 x i8> %xx, <i8 128, i8 128>
204+
%and = and <2 x i8> %x, %y
205+
%z = icmp sgt <2 x i8> %and, %x
206+
ret <2 x i1> %z
207+
}
208+
209+
define i1 @icmp_sle_negx_y(i8 %x, i8 %y) {
210+
; CHECK-LABEL: @icmp_sle_negx_y(
211+
; CHECK-NEXT: [[CX:%.*]] = icmp slt i8 [[X:%.*]], 0
212+
; CHECK-NEXT: call void @llvm.assume(i1 [[CX]])
213+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], [[Y:%.*]]
214+
; CHECK-NEXT: [[Z:%.*]] = icmp sle i8 [[AND]], [[X]]
215+
; CHECK-NEXT: ret i1 [[Z]]
216+
;
217+
%cx = icmp slt i8 %x, 0
218+
call void @llvm.assume(i1 %cx)
219+
%and = and i8 %x, %y
220+
%z = icmp sle i8 %and, %x
221+
ret i1 %z
222+
}
223+
224+
define i1 @icmp_sle_negx_y_fail_maybe_zero(i8 %x, i8 %y) {
225+
; CHECK-LABEL: @icmp_sle_negx_y_fail_maybe_zero(
226+
; CHECK-NEXT: [[CX:%.*]] = icmp slt i8 [[X:%.*]], 1
227+
; CHECK-NEXT: call void @llvm.assume(i1 [[CX]])
228+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], [[Y:%.*]]
229+
; CHECK-NEXT: [[Z:%.*]] = icmp sle i8 [[AND]], [[X]]
230+
; CHECK-NEXT: ret i1 [[Z]]
231+
;
232+
%cx = icmp sle i8 %x, 0
233+
call void @llvm.assume(i1 %cx)
234+
%and = and i8 %x, %y
235+
%z = icmp sle i8 %and, %x
236+
ret i1 %z
237+
}
238+
239+
define i1 @icmp_eq_x_invertable_y_todo(i8 %x, i1 %y) {
240+
; CHECK-LABEL: @icmp_eq_x_invertable_y_todo(
241+
; CHECK-NEXT: [[YY:%.*]] = select i1 [[Y:%.*]], i8 7, i8 24
242+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[YY]], [[X:%.*]]
243+
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], [[X]]
244+
; CHECK-NEXT: ret i1 [[R]]
245+
;
246+
%yy = select i1 %y, i8 7, i8 24
247+
%and = and i8 %x, %yy
248+
%r = icmp eq i8 %x, %and
249+
ret i1 %r
250+
}
251+
252+
define i1 @icmp_eq_x_invertable_y(i8 %x, i8 %y) {
253+
; CHECK-LABEL: @icmp_eq_x_invertable_y(
254+
; CHECK-NEXT: [[YY:%.*]] = xor i8 [[Y:%.*]], -1
255+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[YY]], [[X:%.*]]
256+
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], [[X]]
257+
; CHECK-NEXT: ret i1 [[R]]
258+
;
259+
%yy = xor i8 %y, -1
260+
%and = and i8 %x, %yy
261+
%r = icmp eq i8 %x, %and
262+
ret i1 %r
263+
}
264+
265+
define i1 @icmp_eq_x_invertable_y2_todo(i8 %x, i1 %y) {
266+
; CHECK-LABEL: @icmp_eq_x_invertable_y2_todo(
267+
; CHECK-NEXT: [[YY:%.*]] = select i1 [[Y:%.*]], i8 7, i8 24
268+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[YY]], [[X:%.*]]
269+
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[YY]], [[AND]]
270+
; CHECK-NEXT: ret i1 [[R]]
271+
;
272+
%yy = select i1 %y, i8 7, i8 24
273+
%and = and i8 %x, %yy
274+
%r = icmp eq i8 %yy, %and
275+
ret i1 %r
276+
}
277+
278+
define i1 @icmp_eq_x_invertable_y2(i8 %x, i8 %y) {
279+
; CHECK-LABEL: @icmp_eq_x_invertable_y2(
280+
; CHECK-NEXT: [[YY:%.*]] = xor i8 [[Y:%.*]], -1
281+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[YY]], [[X:%.*]]
282+
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], [[YY]]
283+
; CHECK-NEXT: ret i1 [[R]]
284+
;
285+
%yy = xor i8 %y, -1
286+
%and = and i8 %x, %yy
287+
%r = icmp eq i8 %yy, %and
288+
ret i1 %r
289+
}
290+
291+
define i1 @icmp_eq_x_invertable_y_fail_immconstant(i8 %x, i8 %y) {
292+
; CHECK-LABEL: @icmp_eq_x_invertable_y_fail_immconstant(
293+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 7
294+
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], 7
295+
; CHECK-NEXT: ret i1 [[R]]
296+
;
297+
%and = and i8 %x, 7
298+
%r = icmp eq i8 %and, 7
299+
ret i1 %r
300+
}

0 commit comments

Comments
 (0)