[llvm] 6643132 - [InstCombine] add tests for not+or+neg; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 2 10:16:56 PDT 2021


Author: Sanjay Patel
Date: 2021-04-02T13:16:35-04:00
New Revision: 6643132154535c9911d536146369d0e16d49a591

URL: https://github.com/llvm/llvm-project/commit/6643132154535c9911d536146369d0e16d49a591
DIFF: https://github.com/llvm/llvm-project/commit/6643132154535c9911d536146369d0e16d49a591.diff

LOG: [InstCombine] add tests for not+or+neg; NFC

https://llvm.org/PR45755

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/not.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/not.ll b/llvm/test/Transforms/InstCombine/not.ll
index 6c7d48630473..ff9b49462bf1 100644
--- a/llvm/test/Transforms/InstCombine/not.ll
+++ b/llvm/test/Transforms/InstCombine/not.ll
@@ -1,6 +1,9 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt < %s -instcombine -S | FileCheck %s
 
+declare void @use1(i1)
+declare void @use8(i8)
+
 define i32 @test1(i32 %A) {
 ; CHECK-LABEL: @test1(
 ; CHECK-NEXT:    ret i32 [[A:%.*]]
@@ -12,8 +15,8 @@ define i32 @test1(i32 %A) {
 
 define i1 @invert_icmp(i32 %A, i32 %B) {
 ; CHECK-LABEL: @invert_icmp(
-; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i32 [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT:    ret i1 [[CMP]]
+; CHECK-NEXT:    [[CMP_NOT:%.*]] = icmp sgt i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT:    ret i1 [[CMP_NOT]]
 ;
   %cmp = icmp sle i32 %A, %B
   %not = xor i1 %cmp, true
@@ -78,8 +81,8 @@ define <2 x i1> @not_cmp_constant_vector(<2 x i32> %a) {
 
 define <2 x i1> @test7(<2 x i32> %A, <2 x i32> %B) {
 ; CHECK-LABEL: @test7(
-; CHECK-NEXT:    [[COND:%.*]] = icmp sgt <2 x i32> [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT:    ret <2 x i1> [[COND]]
+; CHECK-NEXT:    [[COND_NOT:%.*]] = icmp sgt <2 x i32> [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT:    ret <2 x i1> [[COND_NOT]]
 ;
   %cond = icmp sle <2 x i32> %A, %B
   %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) {
 
 define i32 @not_ashr_not(i32 %A, i32 %B) {
 ; CHECK-LABEL: @not_ashr_not(
-; CHECK-NEXT:    [[NOT2:%.*]] = ashr i32 [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT:    ret i32 [[NOT2]]
+; CHECK-NEXT:    [[NOT1_NOT:%.*]] = ashr i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT:    ret i32 [[NOT1_NOT]]
 ;
   %not1 = xor i32 %A, -1
   %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) {
   ret i1 %not
 }
 
-declare void @use1(i1)
-
 ; TODO: Missed canonicalization - hoist 'not'?
 
 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) {
   %not = xor i1 %sel, true
   ret i1 %not
 }
+
+define i8 @not_or_neg(i8 %x, i8 %y)  {
+; CHECK-LABEL: @not_or_neg(
+; CHECK-NEXT:    [[S:%.*]] = sub i8 0, [[Y:%.*]]
+; CHECK-NEXT:    [[O:%.*]] = or i8 [[S]], [[X:%.*]]
+; CHECK-NEXT:    [[NOT:%.*]] = xor i8 [[O]], -1
+; CHECK-NEXT:    ret i8 [[NOT]]
+;
+  %s = sub i8 0, %y
+  %o = or i8 %s, %x
+  %not = xor i8 %o, -1
+  ret i8 %not
+}
+
+define <3 x i5> @not_or_neg_commute_vec(<3 x i5> %x, <3 x i5> %p)  {
+; CHECK-LABEL: @not_or_neg_commute_vec(
+; CHECK-NEXT:    [[Y:%.*]] = mul <3 x i5> [[P:%.*]], <i5 1, i5 2, i5 3>
+; CHECK-NEXT:    [[S:%.*]] = sub <3 x i5> <i5 0, i5 0, i5 undef>, [[X:%.*]]
+; CHECK-NEXT:    [[O:%.*]] = or <3 x i5> [[Y]], [[S]]
+; CHECK-NEXT:    [[NOT:%.*]] = xor <3 x i5> [[O]], <i5 -1, i5 undef, i5 -1>
+; CHECK-NEXT:    ret <3 x i5> [[NOT]]
+;
+  %y = mul <3 x i5> %p, <i5 1, i5 2, i5 3> ; thwart complexity-based-canonicalization
+  %s = sub <3 x i5> <i5 0, i5 0, i5 undef>, %x
+  %o = or <3 x i5> %y, %s
+  %not = xor <3 x i5> %o, <i5 -1, i5 undef, i5 -1>
+  ret <3 x i5> %not
+}
+
+define i8 @not_or_neg_use1(i8 %x, i8 %y)  {
+; CHECK-LABEL: @not_or_neg_use1(
+; CHECK-NEXT:    [[S:%.*]] = sub i8 0, [[Y:%.*]]
+; CHECK-NEXT:    call void @use8(i8 [[S]])
+; CHECK-NEXT:    [[O:%.*]] = or i8 [[S]], [[X:%.*]]
+; CHECK-NEXT:    [[NOT:%.*]] = xor i8 [[O]], -1
+; CHECK-NEXT:    ret i8 [[NOT]]
+;
+  %s = sub i8 0, %y
+  call void @use8(i8 %s)
+  %o = or i8 %s, %x
+  %not = xor i8 %o, -1
+  ret i8 %not
+}
+
+define i8 @not_or_neg_use2(i8 %x, i8 %y)  {
+; CHECK-LABEL: @not_or_neg_use2(
+; CHECK-NEXT:    [[S:%.*]] = sub i8 0, [[Y:%.*]]
+; CHECK-NEXT:    [[O:%.*]] = or i8 [[S]], [[X:%.*]]
+; CHECK-NEXT:    call void @use8(i8 [[O]])
+; CHECK-NEXT:    [[NOT:%.*]] = xor i8 [[O]], -1
+; CHECK-NEXT:    ret i8 [[NOT]]
+;
+  %s = sub i8 0, %y
+  %o = or i8 %s, %x
+  call void @use8(i8 %o)
+  %not = xor i8 %o, -1
+  ret i8 %not
+}


        


More information about the llvm-commits mailing list