From 794c34dc35ab70b4e7839e011a787b17dca0363d Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Sun, 23 Apr 2017 13:37:05 +0000 Subject: [PATCH] [InstCombine] add tests for add-to-xor commuted variants; NFC 1 out of the 4 tests commuted the operands, so there's an asymmetry somewhere under this in how we handle these transforms. llvm-svn: 301125 --- llvm/test/Transforms/InstCombine/and-or-not.ll | 52 +++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/llvm/test/Transforms/InstCombine/and-or-not.ll b/llvm/test/Transforms/InstCombine/and-or-not.ll index ac3f366..4398594 100644 --- a/llvm/test/Transforms/InstCombine/and-or-not.ll +++ b/llvm/test/Transforms/InstCombine/and-or-not.ll @@ -4,20 +4,62 @@ ; (a | b) & ~(a & b) --> a ^ b -define i32 @and_to_xor(i32 %a, i32 %b) { -; CHECK-LABEL: @and_to_xor( +define i32 @and_to_xor1(i32 %a, i32 %b) { +; CHECK-LABEL: @and_to_xor1( +; CHECK-NEXT: [[AND2:%.*]] = xor i32 %a, %b +; CHECK-NEXT: ret i32 [[AND2]] +; + %or = or i32 %a, %b + %and = and i32 %a, %b + %not = xor i32 %and, -1 + %and2 = and i32 %or, %not + ret i32 %and2 +} + +; ~(a & b) & (a | b) --> a ^ b + +define i32 @and_to_xor2(i32 %a, i32 %b) { +; CHECK-LABEL: @and_to_xor2( +; CHECK-NEXT: [[AND2:%.*]] = xor i32 %a, %b +; CHECK-NEXT: ret i32 [[AND2]] +; + %or = or i32 %a, %b + %and = and i32 %a, %b + %not = xor i32 %and, -1 + %and2 = and i32 %not, %or + ret i32 %and2 +} + +; (a | b) & ~(b & a) --> a ^ b + +define i32 @and_to_xor3(i32 %a, i32 %b) { +; CHECK-LABEL: @and_to_xor3( ; CHECK-NEXT: [[AND2:%.*]] = xor i32 %b, %a ; CHECK-NEXT: ret i32 [[AND2]] ; - %or = or i32 %b, %a + %or = or i32 %a, %b %and = and i32 %b, %a %not = xor i32 %and, -1 %and2 = and i32 %or, %not ret i32 %and2 } -define <4 x i32> @and_to_xor_vec(<4 x i32> %a, <4 x i32> %b) { -; CHECK-LABEL: @and_to_xor_vec( +; ~(a & b) & (b | a) --> a ^ b + +define i32 @and_to_xor4(i32 %a, i32 %b) { +; CHECK-LABEL: @and_to_xor4( +; CHECK-NEXT: [[AND2:%.*]] = xor i32 %a, %b +; CHECK-NEXT: ret i32 [[AND2]] +; + %or = or i32 %b, %a + %and = and i32 %a, %b + %not = xor i32 %and, -1 + %and2 = and i32 %not, %or + ret i32 %and2 +} + +define <4 x i32> @and_to_xor1_vec(<4 x i32> %a, <4 x i32> %b) { +; CHECK-LABEL: @and_to_xor1_vec( ; CHECK-NEXT: [[AND2:%.*]] = xor <4 x i32> %a, %b ; CHECK-NEXT: ret <4 x i32> [[AND2]] ; -- 2.7.4