[PATCH] D34498: [InstCombine] Add one use checks to or/and->xnor folding
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 22 09:42:50 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306027: [InstCombine] Add one use checks to or/and->xnor folding (authored by ctopper).
Changed prior to commit:
https://reviews.llvm.org/D34498?vs=103524&id=103587#toc
Repository:
rL LLVM
https://reviews.llvm.org/D34498
Files:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/trunk/test/Transforms/InstCombine/and-or-not.ll
Index: llvm/trunk/test/Transforms/InstCombine/and-or-not.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/and-or-not.ll
+++ llvm/trunk/test/Transforms/InstCombine/and-or-not.ll
@@ -527,8 +527,7 @@
; CHECK-NEXT: [[NOTB:%.*]] = xor i32 [[B]], -1
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[NOTA]], [[B]]
; CHECK-NEXT: [[OR2:%.*]] = or i32 [[NOTB]], [[A]]
-; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[B]], [[A]]
-; CHECK-NEXT: [[AND:%.*]] = xor i32 [[TMP1]], -1
+; CHECK-NEXT: [[AND:%.*]] = and i32 [[OR1]], [[OR2]]
; CHECK-NEXT: [[MUL1:%.*]] = mul i32 [[OR1]], [[OR2]]
; CHECK-NEXT: [[MUL2:%.*]] = mul i32 [[MUL1]], [[AND]]
; CHECK-NEXT: ret i32 [[MUL2]]
@@ -552,8 +551,7 @@
; CHECK-NEXT: [[AND:%.*]] = and i32 [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: [[OR:%.*]] = or i32 [[A]], [[B]]
; CHECK-NEXT: [[NOTOR:%.*]] = xor i32 [[OR]], -1
-; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[A]], [[B]]
-; CHECK-NEXT: [[OR2:%.*]] = xor i32 [[TMP1]], -1
+; CHECK-NEXT: [[OR2:%.*]] = or i32 [[AND]], [[NOTOR]]
; CHECK-NEXT: [[MUL1:%.*]] = mul i32 [[AND]], [[NOTOR]]
; CHECK-NEXT: [[MUL2:%.*]] = mul i32 [[MUL1]], [[OR2]]
; CHECK-NEXT: ret i32 [[MUL2]]
Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
===================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -1230,9 +1230,10 @@
// (A | ~B) & (B | ~A) --> ~(A ^ B)
// (~B | A) & (~A | B) --> ~(A ^ B)
// (~B | A) & (B | ~A) --> ~(A ^ B)
- if (match(Op0, m_c_Or(m_Value(A), m_Not(m_Value(B)))) &&
- match(Op1, m_c_Or(m_Not(m_Specific(A)), m_Specific(B))))
- return BinaryOperator::CreateNot(Builder.CreateXor(A, B));
+ if (Op0->hasOneUse() || Op1->hasOneUse())
+ if (match(Op0, m_c_Or(m_Value(A), m_Not(m_Value(B)))) &&
+ match(Op1, m_c_Or(m_Not(m_Specific(A)), m_Specific(B))))
+ return BinaryOperator::CreateNot(Builder.CreateXor(A, B));
return nullptr;
}
@@ -1247,9 +1248,10 @@
// Operand complexity canonicalization guarantees that the 'and' is Op0.
// (A & B) | ~(A | B) --> ~(A ^ B)
// (A & B) | ~(B | A) --> ~(A ^ B)
- if (match(Op0, m_And(m_Value(A), m_Value(B))) &&
- match(Op1, m_Not(m_c_Or(m_Specific(A), m_Specific(B)))))
- return BinaryOperator::CreateNot(Builder.CreateXor(A, B));
+ if (Op0->hasOneUse() || Op1->hasOneUse())
+ if (match(Op0, m_And(m_Value(A), m_Value(B))) &&
+ match(Op1, m_Not(m_c_Or(m_Specific(A), m_Specific(B)))))
+ return BinaryOperator::CreateNot(Builder.CreateXor(A, B));
// (A & ~B) | (~A & B) --> A ^ B
// (A & ~B) | (B & ~A) --> A ^ B
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34498.103587.patch
Type: text/x-patch
Size: 2763 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170622/252168e8/attachment.bin>
More information about the llvm-commits
mailing list