1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
4 declare void @llvm.assume(i1)
5 define <2 x i1> @select_v_ne_z(<2 x i8> %v, <2 x i8> %yy) {
6 ; CHECK-LABEL: @select_v_ne_z(
7 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
9 %y = or <2 x i8> %yy, <i8 1, i8 1>
10 %cmp = icmp ne <2 x i8> %v, zeroinitializer
11 %s = select <2 x i1> %cmp, <2 x i8> %v, <2 x i8> %y
12 %r = icmp eq <2 x i8> %s, zeroinitializer
16 define i1 @select_v_ne_fail(i8 %v, i8 %y) {
17 ; CHECK-LABEL: @select_v_ne_fail(
18 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
19 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
20 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[V:%.*]], 1
21 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
22 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
23 ; CHECK-NEXT: ret i1 [[R]]
25 %ynz = icmp ne i8 %y, 0
26 call void @llvm.assume(i1 %ynz)
27 %cmp = icmp ne i8 %v, 1
28 %s = select i1 %cmp, i8 %v, i8 %y
33 define i1 @select_v_eq_nz(i8 %v, i8 %y) {
34 ; CHECK-LABEL: @select_v_eq_nz(
35 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
36 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
37 ; CHECK-NEXT: ret i1 false
39 %ynz = icmp ne i8 %y, 0
40 call void @llvm.assume(i1 %ynz)
41 %cmp = icmp eq i8 44, %v
42 %s = select i1 %cmp, i8 %v, i8 %y
47 define i1 @inv_select_v_ugt_nz(i8 %v, i8 %C, i8 %y) {
48 ; CHECK-LABEL: @inv_select_v_ugt_nz(
49 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
50 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
51 ; CHECK-NEXT: ret i1 false
53 %ynz = icmp ne i8 %y, 0
54 call void @llvm.assume(i1 %ynz)
55 %cmp = icmp ugt i8 14, %v
56 %s = select i1 %cmp, i8 %y, i8 %v
61 define i1 @inv_select_v_ugt_fail(i8 %v, i8 %C, i8 %y) {
62 ; CHECK-LABEL: @inv_select_v_ugt_fail(
63 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
64 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
65 ; CHECK-NEXT: ret i1 false
67 %ynz = icmp ne i8 %y, 0
68 call void @llvm.assume(i1 %ynz)
69 %cmp = icmp ugt i8 -2, %v
70 %s = select i1 %cmp, i8 %y, i8 %v
75 define <2 x i1> @select_v_ult(<2 x i8> %v, <2 x i8> %C, <2 x i8> %yy) {
76 ; CHECK-LABEL: @select_v_ult(
77 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
79 %y = or <2 x i8> %yy, <i8 1, i8 1>
80 %cmp = icmp ult <2 x i8> %C, %v
81 %s = select <2 x i1> %cmp, <2 x i8> %v, <2 x i8> %y
82 %r = icmp eq <2 x i8> %s, zeroinitializer
86 define <2 x i1> @select_v_uge_nz(<2 x i8> %v, <2 x i8> %yy) {
87 ; CHECK-LABEL: @select_v_uge_nz(
88 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
90 %y = or <2 x i8> %yy, <i8 1, i8 1>
91 %cmp = icmp uge <2 x i8> %v, <i8 1, i8 1>
92 %s = select <2 x i1> %cmp, <2 x i8> %v, <2 x i8> %y
93 %r = icmp eq <2 x i8> %s, zeroinitializer
97 define i1 @inv_select_v_ule(i8 %v, i8 %y) {
98 ; CHECK-LABEL: @inv_select_v_ule(
99 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
100 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
101 ; CHECK-NEXT: ret i1 false
103 %ynz = icmp ne i8 %y, 0
104 call void @llvm.assume(i1 %ynz)
105 %cmp = icmp ule i8 %v, 4
106 %s = select i1 %cmp, i8 %y, i8 %v
107 %r = icmp eq i8 %s, 0
111 define i1 @select_v_sgt_nonneg(i8 %v, i8 %y) {
112 ; CHECK-LABEL: @select_v_sgt_nonneg(
113 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
114 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
115 ; CHECK-NEXT: ret i1 false
117 %ynz = icmp ne i8 %y, 0
118 call void @llvm.assume(i1 %ynz)
119 %cmp = icmp sgt i8 %v, 0
120 %s = select i1 %cmp, i8 %v, i8 %y
121 %r = icmp eq i8 %s, 0
125 define i1 @select_v_sgt_fail(i8 %v, i8 %y) {
126 ; CHECK-LABEL: @select_v_sgt_fail(
127 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
128 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
129 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[V:%.*]], -1
130 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
131 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
132 ; CHECK-NEXT: ret i1 [[R]]
134 %ynz = icmp ne i8 %y, 0
135 call void @llvm.assume(i1 %ynz)
136 %cmp = icmp sgt i8 %v, -1
137 %s = select i1 %cmp, i8 %v, i8 %y
138 %r = icmp eq i8 %s, 0
142 define i1 @inv_select_v_sgt_neg(i8 %v, i8 %y) {
143 ; CHECK-LABEL: @inv_select_v_sgt_neg(
144 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
145 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
146 ; CHECK-NEXT: ret i1 false
148 %ynz = icmp ne i8 %y, 0
149 call void @llvm.assume(i1 %ynz)
150 %cmp = icmp sgt i8 %v, -1
151 %s = select i1 %cmp, i8 %y, i8 %v
152 %r = icmp eq i8 %s, 0
156 define i1 @inv_select_v_sgt_nonneg_nz(i8 %v, i8 %C, i8 %y) {
157 ; CHECK-LABEL: @inv_select_v_sgt_nonneg_nz(
158 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
159 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
160 ; CHECK-NEXT: ret i1 false
162 %ynz = icmp ne i8 %y, 0
163 call void @llvm.assume(i1 %ynz)
164 %cmp = icmp sgt i8 99, %v
165 %s = select i1 %cmp, i8 %y, i8 %v
166 %r = icmp eq i8 %s, 0
170 define i1 @select_v_slt_nonneg(i8 %v, i8 %y) {
171 ; CHECK-LABEL: @select_v_slt_nonneg(
172 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
173 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
174 ; CHECK-NEXT: ret i1 false
176 %ynz = icmp ne i8 %y, 0
177 call void @llvm.assume(i1 %ynz)
178 %cmp = icmp slt i8 0, %v
179 %s = select i1 %cmp, i8 %v, i8 %y
180 %r = icmp eq i8 %s, 0
184 define i1 @select_v_slt_nonneg_fail(i8 %v, i8 %C, i8 %y) {
185 ; CHECK-LABEL: @select_v_slt_nonneg_fail(
186 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
187 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
188 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 -1, [[V:%.*]]
189 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
190 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
191 ; CHECK-NEXT: ret i1 [[R]]
193 %ynz = icmp ne i8 %y, 0
194 call void @llvm.assume(i1 %ynz)
195 %cmp = icmp slt i8 -1, %v
196 %s = select i1 %cmp, i8 %v, i8 %y
197 %r = icmp eq i8 %s, 0
201 define i1 @select_v_slt_neg(i8 %v, i8 %y) {
202 ; CHECK-LABEL: @select_v_slt_neg(
203 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
204 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
205 ; CHECK-NEXT: ret i1 false
207 %ynz = icmp ne i8 %y, 0
208 call void @llvm.assume(i1 %ynz)
209 %cmp = icmp slt i8 %v, -1
210 %s = select i1 %cmp, i8 %v, i8 %y
211 %r = icmp eq i8 %s, 0
215 define i1 @select_v_sge_nonneg_nz(i8 %v, i8 %y) {
216 ; CHECK-LABEL: @select_v_sge_nonneg_nz(
217 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
218 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
219 ; CHECK-NEXT: ret i1 false
221 %ynz = icmp ne i8 %y, 0
222 call void @llvm.assume(i1 %ynz)
223 %cmp = icmp sge i8 %v, 1
224 %s = select i1 %cmp, i8 %v, i8 %y
225 %r = icmp eq i8 %s, 0
229 define i1 @select_v_sge_neg(i8 %v, i8 %y) {
230 ; CHECK-LABEL: @select_v_sge_neg(
231 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
232 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
233 ; CHECK-NEXT: ret i1 false
235 %ynz = icmp ne i8 %y, 0
236 call void @llvm.assume(i1 %ynz)
237 %cmp = icmp sge i8 -3, %v
238 %s = select i1 %cmp, i8 %v, i8 %y
239 %r = icmp eq i8 %s, 0
243 define i1 @inv_select_v_sge_z(i8 %v, i8 %y) {
244 ; CHECK-LABEL: @inv_select_v_sge_z(
245 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
246 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
247 ; CHECK-NEXT: ret i1 false
249 %ynz = icmp ne i8 %y, 0
250 call void @llvm.assume(i1 %ynz)
251 %cmp = icmp sge i8 %v, 0
252 %s = select i1 %cmp, i8 %y, i8 %v
253 %r = icmp eq i8 %s, 0
257 define i1 @inv_select_v_sge_fail(i8 %v, i8 %C, i8 %y) {
258 ; CHECK-LABEL: @inv_select_v_sge_fail(
259 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
260 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
261 ; CHECK-NEXT: ret i1 false
263 %ynz = icmp ne i8 %y, 0
264 call void @llvm.assume(i1 %ynz)
265 %cmp = icmp sge i8 %v, -44
266 %s = select i1 %cmp, i8 %y, i8 %v
267 %r = icmp eq i8 %s, 0
271 define i1 @select_v_sle_neg(i8 %v, i8 %y) {
272 ; CHECK-LABEL: @select_v_sle_neg(
273 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
274 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
275 ; CHECK-NEXT: ret i1 false
277 %ynz = icmp ne i8 %y, 0
278 call void @llvm.assume(i1 %ynz)
279 %cmp = icmp sle i8 %v, -1
280 %s = select i1 %cmp, i8 %v, i8 %y
281 %r = icmp eq i8 %s, 0
285 define i1 @select_v_sle_nonneg_nz(i8 %v, i8 %y) {
286 ; CHECK-LABEL: @select_v_sle_nonneg_nz(
287 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
288 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
289 ; CHECK-NEXT: ret i1 false
291 %ynz = icmp ne i8 %y, 0
292 call void @llvm.assume(i1 %ynz)
293 %cmp = icmp sle i8 1, %v
294 %s = select i1 %cmp, i8 %v, i8 %y
295 %r = icmp eq i8 %s, 0
299 define i1 @select_v_sle_fail(i8 %v, i8 %y) {
300 ; CHECK-LABEL: @select_v_sle_fail(
301 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
302 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
303 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i8 0, [[V:%.*]]
304 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i8 [[V]], i8 [[Y]]
305 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[S]], 0
306 ; CHECK-NEXT: ret i1 [[R]]
308 %ynz = icmp ne i8 %y, 0
309 call void @llvm.assume(i1 %ynz)
310 %cmp = icmp sle i8 0, %v
311 %s = select i1 %cmp, i8 %v, i8 %y
312 %r = icmp eq i8 %s, 0
316 define i1 @inv_select_v_sle_nonneg(i8 %v, i8 %y) {
317 ; CHECK-LABEL: @inv_select_v_sle_nonneg(
318 ; CHECK-NEXT: [[YNZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
319 ; CHECK-NEXT: call void @llvm.assume(i1 [[YNZ]])
320 ; CHECK-NEXT: ret i1 false
322 %ynz = icmp ne i8 %y, 0
323 call void @llvm.assume(i1 %ynz)
324 %cmp = icmp sle i8 %v, 0
325 %s = select i1 %cmp, i8 %y, i8 %v
326 %r = icmp eq i8 %s, 0