[llvm] r290127 - [InstCombine] use commutative matcher for pattern with commutative operators
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 19 10:35:38 PST 2016
Author: spatel
Date: Mon Dec 19 12:35:37 2016
New Revision: 290127
URL: http://llvm.org/viewvc/llvm-project?rev=290127&view=rev
Log:
[InstCombine] use commutative matcher for pattern with commutative operators
This is a case that was missed in:
https://reviews.llvm.org/rL290067
...and it would regress if we fix operand complexity (PR28296).
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/trunk/test/Transforms/InstCombine/or.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=290127&r1=290126&r2=290127&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Mon Dec 19 12:35:37 2016
@@ -2263,9 +2263,11 @@ Instruction *InstCombiner::visitOr(Binar
match(Op1, m_Xor(m_Specific(A), m_Specific(B))))
return BinaryOperator::CreateXor(A, B);
- // (A ^ B) | ( A & (~B)) -> (A ^ B)
- if (match(Op0, m_Xor(m_Value(A), m_Value(B))) &&
- match(Op1, m_And(m_Specific(A), m_Not(m_Specific(B)))))
+ // Commute the 'or' operands.
+ // (A ^ B) | (A & ~B) -> (A ^ B)
+ // (A ^ B) | (~B & A) -> (A ^ B)
+ if (match(Op1, m_c_And(m_Value(A), m_Not(m_Value(B)))) &&
+ match(Op0, m_Xor(m_Specific(A), m_Specific(B))))
return BinaryOperator::CreateXor(A, B);
// (A & C)|(B & D)
Modified: llvm/trunk/test/Transforms/InstCombine/or.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/or.ll?rev=290127&r1=290126&r2=290127&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/or.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/or.ll Mon Dec 19 12:35:37 2016
@@ -596,7 +596,7 @@ define i32 @test42_commuted_xor(i32 %a,
ret i32 %or
}
-; Commute operands of the 'or'.
+; (A & ~B) | (A ^ B) -> A ^ B
define i32 @test43(i32 %a, i32 %b) {
; CHECK-LABEL: @test43(
@@ -622,6 +622,9 @@ define i32 @test43_commuted_and(i32 %a,
ret i32 %or
}
+; Commute operands of the 'or'.
+; (A ^ B) | (A & ~B) -> A ^ B
+
define i32 @test44(i32 %a, i32 %b) {
; CHECK-LABEL: @test44(
; CHECK-NEXT: [[OR:%.*]] = xor i32 %a, %b
@@ -633,6 +636,18 @@ define i32 @test44(i32 %a, i32 %b) {
%or = or i32 %xor, %and
ret i32 %or
}
+
+define i32 @test44_commuted_and(i32 %a, i32 %b) {
+; CHECK-LABEL: @test44_commuted_and(
+; CHECK-NEXT: [[OR:%.*]] = xor i32 %a, %b
+; CHECK-NEXT: ret i32 [[OR]]
+;
+ %xor = xor i32 %a, %b
+ %neg = xor i32 %b, -1
+ %and = and i32 %neg, %a
+ %or = or i32 %xor, %and
+ ret i32 %or
+}
define i32 @test45(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @test45(
More information about the llvm-commits
mailing list