diff --git a/llvm/test/Transforms/InstCombine/and-or.ll b/llvm/test/Transforms/InstCombine/and-or.ll index 239080e5211c50..9fb020bed9e33d 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]], +; CHECK-NEXT: [[T2:%.*]] = and <2 x i7> [[B]], +; 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, + %t2 = and <2 x i7> %b, + %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 f0a3f58a83eca9..4dd86c66018eeb 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]], +; CHECK-NEXT: [[AND2:%.*]] = and <2 x i9> [[B]], +; 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, + %and2 = and <2 x i9> %b, + %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]], +; CHECK-NEXT: [[AND2:%.*]] = and <2 x i9> [[B]], +; 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, + %and2 = and <2 x i9> %b, + %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