Skip to content

Commit b24b940

Browse files
rotaterightmemfrob
authored andcommitted
[InstCombine] add tests for not+or+neg; NFC
https://llvm.org/PR45755
1 parent 57956c5 commit b24b940

File tree

1 file changed

+67
-8
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+67
-8
lines changed

llvm/test/Transforms/InstCombine/not.ll

Lines changed: 67 additions & 8 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 @use1(i1)
5+
declare void @use8(i8)
6+
47
define i32 @test1(i32 %A) {
58
; CHECK-LABEL: @test1(
69
; CHECK-NEXT: ret i32 [[A:%.*]]
@@ -12,8 +15,8 @@ define i32 @test1(i32 %A) {
1215

1316
define i1 @invert_icmp(i32 %A, i32 %B) {
1417
; CHECK-LABEL: @invert_icmp(
15-
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[A:%.*]], [[B:%.*]]
16-
; CHECK-NEXT: ret i1 [[CMP]]
18+
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp sgt i32 [[A:%.*]], [[B:%.*]]
19+
; CHECK-NEXT: ret i1 [[CMP_NOT]]
1720
;
1821
%cmp = icmp sle i32 %A, %B
1922
%not = xor i1 %cmp, true
@@ -78,8 +81,8 @@ define <2 x i1> @not_cmp_constant_vector(<2 x i32> %a) {
7881

7982
define <2 x i1> @test7(<2 x i32> %A, <2 x i32> %B) {
8083
; CHECK-LABEL: @test7(
81-
; CHECK-NEXT: [[COND:%.*]] = icmp sgt <2 x i32> [[A:%.*]], [[B:%.*]]
82-
; CHECK-NEXT: ret <2 x i1> [[COND]]
84+
; CHECK-NEXT: [[COND_NOT:%.*]] = icmp sgt <2 x i32> [[A:%.*]], [[B:%.*]]
85+
; CHECK-NEXT: ret <2 x i1> [[COND_NOT]]
8386
;
8487
%cond = icmp sle <2 x i32> %A, %B
8588
%Ret = xor <2 x i1> %cond, <i1 true, i1 true>
@@ -88,8 +91,8 @@ define <2 x i1> @test7(<2 x i32> %A, <2 x i32> %B) {
8891

8992
define i32 @not_ashr_not(i32 %A, i32 %B) {
9093
; CHECK-LABEL: @not_ashr_not(
91-
; CHECK-NEXT: [[NOT2:%.*]] = ashr i32 [[A:%.*]], [[B:%.*]]
92-
; CHECK-NEXT: ret i32 [[NOT2]]
94+
; CHECK-NEXT: [[NOT1_NOT:%.*]] = ashr i32 [[A:%.*]], [[B:%.*]]
95+
; CHECK-NEXT: ret i32 [[NOT1_NOT]]
9396
;
9497
%not1 = xor i32 %A, -1
9598
%ashr = ashr i32 %not1, %B
@@ -265,8 +268,6 @@ define i1 @not_select_cmp_cmp(i32 %x, i32 %y, float %z, float %w, i1 %cond) {
265268
ret i1 %not
266269
}
267270

268-
declare void @use1(i1)
269-
270271
; TODO: Missed canonicalization - hoist 'not'?
271272

272273
define i1 @not_select_cmp_cmp_extra_use1(i32 %x, i32 %y, float %z, float %w, i1 %cond) {
@@ -404,3 +405,61 @@ define i1 @not_select_cmpf_extra_use(i1 %x, i32 %z, i32 %w, i1 %cond) {
404405
%not = xor i1 %sel, true
405406
ret i1 %not
406407
}
408+
409+
define i8 @not_or_neg(i8 %x, i8 %y) {
410+
; CHECK-LABEL: @not_or_neg(
411+
; CHECK-NEXT: [[S:%.*]] = sub i8 0, [[Y:%.*]]
412+
; CHECK-NEXT: [[O:%.*]] = or i8 [[S]], [[X:%.*]]
413+
; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[O]], -1
414+
; CHECK-NEXT: ret i8 [[NOT]]
415+
;
416+
%s = sub i8 0, %y
417+
%o = or i8 %s, %x
418+
%not = xor i8 %o, -1
419+
ret i8 %not
420+
}
421+
422+
define <3 x i5> @not_or_neg_commute_vec(<3 x i5> %x, <3 x i5> %p) {
423+
; CHECK-LABEL: @not_or_neg_commute_vec(
424+
; CHECK-NEXT: [[Y:%.*]] = mul <3 x i5> [[P:%.*]], <i5 1, i5 2, i5 3>
425+
; CHECK-NEXT: [[S:%.*]] = sub <3 x i5> <i5 0, i5 0, i5 undef>, [[X:%.*]]
426+
; CHECK-NEXT: [[O:%.*]] = or <3 x i5> [[Y]], [[S]]
427+
; CHECK-NEXT: [[NOT:%.*]] = xor <3 x i5> [[O]], <i5 -1, i5 undef, i5 -1>
428+
; CHECK-NEXT: ret <3 x i5> [[NOT]]
429+
;
430+
%y = mul <3 x i5> %p, <i5 1, i5 2, i5 3> ; thwart complexity-based-canonicalization
431+
%s = sub <3 x i5> <i5 0, i5 0, i5 undef>, %x
432+
%o = or <3 x i5> %y, %s
433+
%not = xor <3 x i5> %o, <i5 -1, i5 undef, i5 -1>
434+
ret <3 x i5> %not
435+
}
436+
437+
define i8 @not_or_neg_use1(i8 %x, i8 %y) {
438+
; CHECK-LABEL: @not_or_neg_use1(
439+
; CHECK-NEXT: [[S:%.*]] = sub i8 0, [[Y:%.*]]
440+
; CHECK-NEXT: call void @use8(i8 [[S]])
441+
; CHECK-NEXT: [[O:%.*]] = or i8 [[S]], [[X:%.*]]
442+
; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[O]], -1
443+
; CHECK-NEXT: ret i8 [[NOT]]
444+
;
445+
%s = sub i8 0, %y
446+
call void @use8(i8 %s)
447+
%o = or i8 %s, %x
448+
%not = xor i8 %o, -1
449+
ret i8 %not
450+
}
451+
452+
define i8 @not_or_neg_use2(i8 %x, i8 %y) {
453+
; CHECK-LABEL: @not_or_neg_use2(
454+
; CHECK-NEXT: [[S:%.*]] = sub i8 0, [[Y:%.*]]
455+
; CHECK-NEXT: [[O:%.*]] = or i8 [[S]], [[X:%.*]]
456+
; CHECK-NEXT: call void @use8(i8 [[O]])
457+
; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[O]], -1
458+
; CHECK-NEXT: ret i8 [[NOT]]
459+
;
460+
%s = sub i8 0, %y
461+
%o = or i8 %s, %x
462+
call void @use8(i8 %o)
463+
%not = xor i8 %o, -1
464+
ret i8 %not
465+
}

0 commit comments

Comments
 (0)