Skip to content

Commit cd76fa7

Browse files
committed
[InstCombine] add tests for icmp of negated op; NFC
1 parent 38e3b30 commit cd76fa7

File tree

1 file changed

+283
-0
lines changed

1 file changed

+283
-0
lines changed

llvm/test/Transforms/InstCombine/icmp-sub.ll

Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
22
; RUN: opt < %s -instcombine -S | FileCheck %s
33

4+
declare void @use(i32)
5+
declare void @use_vec(<2 x i8>)
6+
47
define i1 @test_nuw_and_unsigned_pred(i64 %x) {
58
; CHECK-LABEL: @test_nuw_and_unsigned_pred(
69
; CHECK-NEXT: [[Z:%.*]] = icmp ugt i64 [[X:%.*]], 7
@@ -185,3 +188,283 @@ define <2 x i1> @icmp_eq_sub_non_splat2(<2 x i32> %a) {
185188
%cmp = icmp eq <2 x i32> %sub, <i32 10, i32 11>
186189
ret <2 x i1> %cmp
187190
}
191+
192+
define i1 @neg_sgt_42(i32 %x) {
193+
; CHECK-LABEL: @neg_sgt_42(
194+
; CHECK-NEXT: [[NEGX:%.*]] = sub i32 0, [[X:%.*]]
195+
; CHECK-NEXT: [[R:%.*]] = icmp sgt i32 [[NEGX]], 42
196+
; CHECK-NEXT: ret i1 [[R]]
197+
;
198+
%negx = sub i32 0, %x
199+
%r = icmp sgt i32 %negx, 42
200+
ret i1 %r
201+
}
202+
203+
define i1 @neg_eq_43(i32 %x) {
204+
; CHECK-LABEL: @neg_eq_43(
205+
; CHECK-NEXT: [[NEGX:%.*]] = sub i32 0, [[X:%.*]]
206+
; CHECK-NEXT: call void @use(i32 [[NEGX]])
207+
; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[NEGX]], 43
208+
; CHECK-NEXT: ret i1 [[R]]
209+
;
210+
%negx = sub i32 0, %x
211+
call void @use(i32 %negx)
212+
%r = icmp eq i32 %negx, 43
213+
ret i1 %r
214+
}
215+
216+
define i1 @neg_ne_44(i32 %x) {
217+
; CHECK-LABEL: @neg_ne_44(
218+
; CHECK-NEXT: [[NEGX:%.*]] = sub i32 0, [[X:%.*]]
219+
; CHECK-NEXT: call void @use(i32 [[NEGX]])
220+
; CHECK-NEXT: [[R:%.*]] = icmp ne i32 [[NEGX]], 44
221+
; CHECK-NEXT: ret i1 [[R]]
222+
;
223+
%negx = sub i32 0, %x
224+
call void @use(i32 %negx)
225+
%r = icmp ne i32 %negx, 44
226+
ret i1 %r
227+
}
228+
229+
define i1 @neg_nsw_eq_45(i32 %x) {
230+
; CHECK-LABEL: @neg_nsw_eq_45(
231+
; CHECK-NEXT: [[NEGX:%.*]] = sub nsw i32 0, [[X:%.*]]
232+
; CHECK-NEXT: call void @use(i32 [[NEGX]])
233+
; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[NEGX]], 45
234+
; CHECK-NEXT: ret i1 [[R]]
235+
;
236+
%negx = sub nsw i32 0, %x
237+
call void @use(i32 %negx)
238+
%r = icmp eq i32 %negx, 45
239+
ret i1 %r
240+
}
241+
242+
define i1 @neg_nsw_ne_46(i32 %x) {
243+
; CHECK-LABEL: @neg_nsw_ne_46(
244+
; CHECK-NEXT: [[NEGX:%.*]] = sub nsw i32 0, [[X:%.*]]
245+
; CHECK-NEXT: call void @use(i32 [[NEGX]])
246+
; CHECK-NEXT: [[R:%.*]] = icmp ne i32 [[NEGX]], 46
247+
; CHECK-NEXT: ret i1 [[R]]
248+
;
249+
%negx = sub nsw i32 0, %x
250+
call void @use(i32 %negx)
251+
%r = icmp ne i32 %negx, 46
252+
ret i1 %r
253+
}
254+
255+
define i1 @subC_eq(i32 %x) {
256+
; CHECK-LABEL: @subC_eq(
257+
; CHECK-NEXT: [[SUBX:%.*]] = sub i32 -2147483648, [[X:%.*]]
258+
; CHECK-NEXT: call void @use(i32 [[SUBX]])
259+
; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[SUBX]], 43
260+
; CHECK-NEXT: ret i1 [[R]]
261+
;
262+
%subx = sub i32 -2147483648, %x
263+
call void @use(i32 %subx)
264+
%r = icmp eq i32 %subx, 43
265+
ret i1 %r
266+
}
267+
268+
define <2 x i1> @subC_ne(<2 x i8> %x) {
269+
; CHECK-LABEL: @subC_ne(
270+
; CHECK-NEXT: [[SUBX:%.*]] = sub <2 x i8> <i8 -6, i8 -128>, [[X:%.*]]
271+
; CHECK-NEXT: call void @use_vec(<2 x i8> [[SUBX]])
272+
; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i8> [[SUBX]], <i8 -44, i8 -44>
273+
; CHECK-NEXT: ret <2 x i1> [[R]]
274+
;
275+
%subx = sub <2 x i8> <i8 -6, i8 -128>, %x
276+
call void @use_vec(<2 x i8> %subx)
277+
%r = icmp ne <2 x i8> %subx, <i8 -44, i8 -44>
278+
ret <2 x i1> %r
279+
}
280+
281+
define i1 @subC_nsw_eq(i32 %x) {
282+
; CHECK-LABEL: @subC_nsw_eq(
283+
; CHECK-NEXT: [[SUBX:%.*]] = sub nsw i32 -100, [[X:%.*]]
284+
; CHECK-NEXT: call void @use(i32 [[SUBX]])
285+
; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[SUBX]], -2147483648
286+
; CHECK-NEXT: ret i1 [[R]]
287+
;
288+
%subx = sub nsw i32 -100, %x
289+
call void @use(i32 %subx)
290+
%r = icmp eq i32 %subx, -2147483648
291+
ret i1 %r
292+
}
293+
294+
define i1 @subC_nsw_ne(i32 %x) {
295+
; CHECK-LABEL: @subC_nsw_ne(
296+
; CHECK-NEXT: [[SUBX:%.*]] = sub nsw i32 -2147483647, [[X:%.*]]
297+
; CHECK-NEXT: call void @use(i32 [[SUBX]])
298+
; CHECK-NEXT: [[R:%.*]] = icmp ne i32 [[SUBX]], 46
299+
; CHECK-NEXT: ret i1 [[R]]
300+
;
301+
%subx = sub nsw i32 -2147483647, %x
302+
call void @use(i32 %subx)
303+
%r = icmp ne i32 %subx, 46
304+
ret i1 %r
305+
}
306+
307+
define i1 @neg_slt_42(i128 %x) {
308+
; CHECK-LABEL: @neg_slt_42(
309+
; CHECK-NEXT: [[NEGX:%.*]] = sub i128 0, [[X:%.*]]
310+
; CHECK-NEXT: [[R:%.*]] = icmp slt i128 [[NEGX]], 42
311+
; CHECK-NEXT: ret i1 [[R]]
312+
;
313+
%negx = sub i128 0, %x
314+
%r = icmp slt i128 %negx, 42
315+
ret i1 %r
316+
}
317+
318+
define <2 x i1> @neg_ugt_42_splat(<2 x i7> %x) {
319+
; CHECK-LABEL: @neg_ugt_42_splat(
320+
; CHECK-NEXT: [[NEGX:%.*]] = sub <2 x i7> zeroinitializer, [[X:%.*]]
321+
; CHECK-NEXT: [[R:%.*]] = icmp ugt <2 x i7> [[NEGX]], <i7 42, i7 42>
322+
; CHECK-NEXT: ret <2 x i1> [[R]]
323+
;
324+
%negx = sub <2 x i7> zeroinitializer, %x
325+
%r = icmp ugt <2 x i7> %negx, <i7 42, i7 42>
326+
ret <2 x i1> %r
327+
}
328+
329+
define i1 @neg_sgt_42_use(i32 %x) {
330+
; CHECK-LABEL: @neg_sgt_42_use(
331+
; CHECK-NEXT: [[NEGX:%.*]] = sub i32 0, [[X:%.*]]
332+
; CHECK-NEXT: call void @use(i32 [[NEGX]])
333+
; CHECK-NEXT: [[R:%.*]] = icmp sgt i32 [[NEGX]], 42
334+
; CHECK-NEXT: ret i1 [[R]]
335+
;
336+
%negx = sub i32 0, %x
337+
call void @use(i32 %negx)
338+
%r = icmp sgt i32 %negx, 42
339+
ret i1 %r
340+
}
341+
342+
; Test common/edge cases with signed pred.
343+
344+
define i1 @neg_slt_n1(i8 %x) {
345+
; CHECK-LABEL: @neg_slt_n1(
346+
; CHECK-NEXT: [[NEGX:%.*]] = sub i8 0, [[X:%.*]]
347+
; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[NEGX]], -1
348+
; CHECK-NEXT: ret i1 [[R]]
349+
;
350+
%negx = sub i8 0, %x
351+
%r = icmp slt i8 %negx, -1
352+
ret i1 %r
353+
}
354+
355+
define i1 @neg_slt_0(i8 %x) {
356+
; CHECK-LABEL: @neg_slt_0(
357+
; CHECK-NEXT: [[NEGX:%.*]] = sub i8 0, [[X:%.*]]
358+
; CHECK-NEXT: [[ISNEGNEG:%.*]] = icmp slt i8 [[NEGX]], 0
359+
; CHECK-NEXT: ret i1 [[ISNEGNEG]]
360+
;
361+
%negx = sub i8 0, %x
362+
%isnegneg = icmp slt i8 %negx, 0
363+
ret i1 %isnegneg
364+
}
365+
366+
define i1 @neg_slt_1(i8 %x) {
367+
; CHECK-LABEL: @neg_slt_1(
368+
; CHECK-NEXT: [[NEGX:%.*]] = sub i8 0, [[X:%.*]]
369+
; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[NEGX]], 1
370+
; CHECK-NEXT: ret i1 [[R]]
371+
;
372+
%negx = sub i8 0, %x
373+
%r = icmp slt i8 %negx, 1
374+
ret i1 %r
375+
}
376+
377+
define i1 @neg_sgt_n1(i8 %x) {
378+
; CHECK-LABEL: @neg_sgt_n1(
379+
; CHECK-NEXT: [[NEGX:%.*]] = sub i8 0, [[X:%.*]]
380+
; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[NEGX]], -1
381+
; CHECK-NEXT: ret i1 [[R]]
382+
;
383+
%negx = sub i8 0, %x
384+
%r = icmp sgt i8 %negx, -1
385+
ret i1 %r
386+
}
387+
388+
define i1 @neg_sgt_0(i8 %x) {
389+
; CHECK-LABEL: @neg_sgt_0(
390+
; CHECK-NEXT: [[NEGX:%.*]] = sub i8 0, [[X:%.*]]
391+
; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[NEGX]], 0
392+
; CHECK-NEXT: ret i1 [[R]]
393+
;
394+
%negx = sub i8 0, %x
395+
%r = icmp sgt i8 %negx, 0
396+
ret i1 %r
397+
}
398+
399+
define i1 @neg_sgt_1(i8 %x) {
400+
; CHECK-LABEL: @neg_sgt_1(
401+
; CHECK-NEXT: [[NEGX:%.*]] = sub i8 0, [[X:%.*]]
402+
; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[NEGX]], 1
403+
; CHECK-NEXT: ret i1 [[R]]
404+
;
405+
%negx = sub i8 0, %x
406+
%r = icmp sgt i8 %negx, 1
407+
ret i1 %r
408+
}
409+
410+
; Test common/edge cases with signed pred and nsw.
411+
412+
define i1 @neg_nsw_slt_n1(i8 %x) {
413+
; CHECK-LABEL: @neg_nsw_slt_n1(
414+
; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[X:%.*]], 1
415+
; CHECK-NEXT: ret i1 [[R]]
416+
;
417+
%negx = sub nsw i8 0, %x
418+
%r = icmp slt i8 %negx, -1
419+
ret i1 %r
420+
}
421+
422+
define i1 @neg_nsw_slt_0(i8 %x) {
423+
; CHECK-LABEL: @neg_nsw_slt_0(
424+
; CHECK-NEXT: [[ISNEGNEG:%.*]] = icmp sgt i8 [[X:%.*]], 0
425+
; CHECK-NEXT: ret i1 [[ISNEGNEG]]
426+
;
427+
%negx = sub nsw i8 0, %x
428+
%isnegneg = icmp slt i8 %negx, 0
429+
ret i1 %isnegneg
430+
}
431+
432+
define i1 @neg_nsw_slt_1(i8 %x) {
433+
; CHECK-LABEL: @neg_nsw_slt_1(
434+
; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[X:%.*]], -1
435+
; CHECK-NEXT: ret i1 [[R]]
436+
;
437+
%negx = sub nsw i8 0, %x
438+
%r = icmp slt i8 %negx, 1
439+
ret i1 %r
440+
}
441+
442+
define i1 @neg_nsw_sgt_n1(i8 %x) {
443+
; CHECK-LABEL: @neg_nsw_sgt_n1(
444+
; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[X:%.*]], 1
445+
; CHECK-NEXT: ret i1 [[R]]
446+
;
447+
%negx = sub nsw i8 0, %x
448+
%r = icmp sgt i8 %negx, -1
449+
ret i1 %r
450+
}
451+
452+
define i1 @neg_nsw_sgt_0(i8 %x) {
453+
; CHECK-LABEL: @neg_nsw_sgt_0(
454+
; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[X:%.*]], 0
455+
; CHECK-NEXT: ret i1 [[R]]
456+
;
457+
%negx = sub nsw i8 0, %x
458+
%r = icmp sgt i8 %negx, 0
459+
ret i1 %r
460+
}
461+
462+
define i1 @neg_nsw_sgt_1(i8 %x) {
463+
; CHECK-LABEL: @neg_nsw_sgt_1(
464+
; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[X:%.*]], -1
465+
; CHECK-NEXT: ret i1 [[R]]
466+
;
467+
%negx = sub nsw i8 0, %x
468+
%r = icmp sgt i8 %negx, 1
469+
ret i1 %r
470+
}

0 commit comments

Comments
 (0)