[llvm] ae89841 - [InstCombine] add tests for bitwise logic folds; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 29 11:38:01 PDT 2021


Author: Sanjay Patel
Date: 2021-10-29T14:22:49-04:00
New Revision: ae8984111d8316cb33992deca34d49704344069a

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

LOG: [InstCombine] add tests for bitwise logic folds; NFC

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/and-or.ll
    llvm/test/Transforms/InstCombine/or-xor.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/and-or.ll b/llvm/test/Transforms/InstCombine/and-or.ll
index 239080e5211c..9fb020bed9e3 100644
--- a/llvm/test/Transforms/InstCombine/and-or.ll
+++ b/llvm/test/Transforms/InstCombine/and-or.ll
@@ -1,8 +1,10 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt < %s -instcombine -S | FileCheck %s
 
-define i32 @func1(i32 %a, i32 %b) {
-; CHECK-LABEL: @func1(
+; ((b | a) & C1) | (b & C2) -> (a & C1) | b iff C1 == ~C2
+
+define i32 @or_and_not_constant_commute0(i32 %a, i32 %b) {
+; CHECK-LABEL: @or_and_not_constant_commute0(
 ; CHECK-NEXT:    [[TMP1:%.*]] = and i32 [[A:%.*]], 1
 ; CHECK-NEXT:    [[T3:%.*]] = or i32 [[TMP1]], [[B:%.*]]
 ; CHECK-NEXT:    ret i32 [[T3]]
@@ -14,8 +16,8 @@ define i32 @func1(i32 %a, i32 %b) {
   ret i32 %t3
 }
 
-define i32 @func2(i32 %a, i32 %b) {
-; CHECK-LABEL: @func2(
+define i32 @or_and_not_constant_commute1(i32 %a, i32 %b) {
+; CHECK-LABEL: @or_and_not_constant_commute1(
 ; CHECK-NEXT:    [[TMP1:%.*]] = and i32 [[A:%.*]], 1
 ; CHECK-NEXT:    [[T3:%.*]] = or i32 [[TMP1]], [[B:%.*]]
 ; CHECK-NEXT:    ret i32 [[T3]]
@@ -27,8 +29,8 @@ define i32 @func2(i32 %a, i32 %b) {
   ret i32 %t3
 }
 
-define i32 @func3(i32 %a, i32 %b) {
-; CHECK-LABEL: @func3(
+define i32 @or_and_not_constant_commute2(i32 %a, i32 %b) {
+; CHECK-LABEL: @or_and_not_constant_commute2(
 ; CHECK-NEXT:    [[TMP1:%.*]] = and i32 [[A:%.*]], 1
 ; CHECK-NEXT:    [[T3:%.*]] = or i32 [[TMP1]], [[B:%.*]]
 ; CHECK-NEXT:    ret i32 [[T3]]
@@ -40,8 +42,8 @@ define i32 @func3(i32 %a, i32 %b) {
   ret i32 %t3
 }
 
-define i32 @func4(i32 %a, i32 %b) {
-; CHECK-LABEL: @func4(
+define i32 @or_and_not_constant_commute3(i32 %a, i32 %b) {
+; CHECK-LABEL: @or_and_not_constant_commute3(
 ; CHECK-NEXT:    [[TMP1:%.*]] = and i32 [[A:%.*]], 1
 ; CHECK-NEXT:    [[T3:%.*]] = or i32 [[TMP1]], [[B:%.*]]
 ; CHECK-NEXT:    ret i32 [[T3]]
@@ -53,6 +55,21 @@ define i32 @func4(i32 %a, i32 %b) {
   ret i32 %t3
 }
 
+define <2 x i7> @or_and_not_constant_commute0_splat(<2 x i7> %a, <2 x i7> %b) {
+; CHECK-LABEL: @or_and_not_constant_commute0_splat(
+; CHECK-NEXT:    [[T:%.*]] = or <2 x i7> [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT:    [[T1:%.*]] = and <2 x i7> [[T]], <i7 42, i7 42>
+; CHECK-NEXT:    [[T2:%.*]] = and <2 x i7> [[B]], <i7 -43, i7 -43>
+; CHECK-NEXT:    [[T3:%.*]] = or <2 x i7> [[T1]], [[T2]]
+; CHECK-NEXT:    ret <2 x i7> [[T3]]
+;
+  %t = or <2 x i7> %b, %a
+  %t1 = and <2 x i7> %t, <i7 42, i7 42>
+  %t2 = and <2 x i7> %b, <i7 -43, i7 -43>
+  %t3 = or <2 x i7> %t1, %t2
+  ret <2 x i7> %t3
+}
+
 ; Check variants of:
 ; and ({x}or X, Y), C --> {x}or X, (and Y, C)
 ; ...in the following 5 tests.

diff  --git a/llvm/test/Transforms/InstCombine/or-xor.ll b/llvm/test/Transforms/InstCombine/or-xor.ll
index f0a3f58a83ec..4dd86c66018e 100644
--- a/llvm/test/Transforms/InstCombine/or-xor.ll
+++ b/llvm/test/Transforms/InstCombine/or-xor.ll
@@ -273,8 +273,10 @@ define i32 @test15_commuted(i32 %x, i32 %y) {
   ret i32 %xor
 }
 
-define i32 @test16(i32 %a, i32 %b) {
-; CHECK-LABEL: @test16(
+; ((a ^ b) & C1) | (b & C2) -> (a & C1) ^ b iff C1 == ~C2
+
+define i32 @or_and_xor_not_constant_commute0(i32 %a, i32 %b) {
+; CHECK-LABEL: @or_and_xor_not_constant_commute0(
 ; CHECK-NEXT:    [[TMP1:%.*]] = and i32 [[A:%.*]], 1
 ; CHECK-NEXT:    [[XOR:%.*]] = xor i32 [[TMP1]], [[B:%.*]]
 ; CHECK-NEXT:    ret i32 [[XOR]]
@@ -286,6 +288,49 @@ define i32 @test16(i32 %a, i32 %b) {
   ret i32 %xor
 }
 
+define i9 @or_and_xor_not_constant_commute1(i9 %a, i9 %b) {
+; CHECK-LABEL: @or_and_xor_not_constant_commute1(
+; CHECK-NEXT:    [[TMP1:%.*]] = and i9 [[A:%.*]], 42
+; CHECK-NEXT:    [[XOR:%.*]] = xor i9 [[TMP1]], [[B:%.*]]
+; CHECK-NEXT:    ret i9 [[XOR]]
+;
+  %or = xor i9 %b, %a
+  %and1 = and i9 %or, 42
+  %and2 = and i9 %b, -43
+  %xor = or i9 %and1, %and2
+  ret i9 %xor
+}
+
+define <2 x i9> @or_and_xor_not_constant_commute2_splat(<2 x i9> %a, <2 x i9> %b) {
+; CHECK-LABEL: @or_and_xor_not_constant_commute2_splat(
+; CHECK-NEXT:    [[OR:%.*]] = xor <2 x i9> [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT:    [[AND1:%.*]] = and <2 x i9> [[OR]], <i9 42, i9 42>
+; CHECK-NEXT:    [[AND2:%.*]] = and <2 x i9> [[B]], <i9 -43, i9 -43>
+; CHECK-NEXT:    [[XOR:%.*]] = or <2 x i9> [[AND2]], [[AND1]]
+; CHECK-NEXT:    ret <2 x i9> [[XOR]]
+;
+  %or = xor <2 x i9> %b, %a
+  %and1 = and <2 x i9> %or, <i9 42, i9 42>
+  %and2 = and <2 x i9> %b, <i9 -43, i9 -43>
+  %xor = or <2 x i9> %and2, %and1
+  ret <2 x i9> %xor
+}
+
+define <2 x i9> @or_and_xor_not_constant_commute3_splat(<2 x i9> %a, <2 x i9> %b) {
+; CHECK-LABEL: @or_and_xor_not_constant_commute3_splat(
+; CHECK-NEXT:    [[OR:%.*]] = xor <2 x i9> [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT:    [[AND1:%.*]] = and <2 x i9> [[OR]], <i9 42, i9 42>
+; CHECK-NEXT:    [[AND2:%.*]] = and <2 x i9> [[B]], <i9 -43, i9 -43>
+; CHECK-NEXT:    [[XOR:%.*]] = or <2 x i9> [[AND2]], [[AND1]]
+; CHECK-NEXT:    ret <2 x i9> [[XOR]]
+;
+  %or = xor <2 x i9> %a, %b
+  %and1 = and <2 x i9> %or, <i9 42, i9 42>
+  %and2 = and <2 x i9> %b, <i9 -43, i9 -43>
+  %xor = or <2 x i9> %and2, %and1
+  ret <2 x i9> %xor
+}
+
 define i8 @not_or(i8 %x) {
 ; CHECK-LABEL: @not_or(
 ; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1


        


More information about the llvm-commits mailing list