diff options
author | Sanjay Patel <spatel@rotateright.com> | 2017-04-24 18:24:36 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2017-04-24 18:24:36 +0000 |
commit | 0889225f51791cb4e8219a9dd96c3144122348ec (patch) | |
tree | cd69e38b730176c23efafa34134de4931b720ef9 /llvm/lib/Analysis/InstructionSimplify.cpp | |
parent | f2fc5b068e011455a4857cdc9349055c5a8b5221 (diff) | |
download | bcm5719-llvm-0889225f51791cb4e8219a9dd96c3144122348ec.tar.gz bcm5719-llvm-0889225f51791cb4e8219a9dd96c3144122348ec.zip |
[InstSimplify] move (A & ~B) | (A ^ B) -> (A ^ B) from InstCombine
This is a straight cut and paste, but there's a bigger problem: if this
fold exists for simplifyOr, there should be a DeMorganized version for
simplifyAnd. But more than that, we have a patchwork of ad hoc logic
optimizations in InstCombine. There should be some structure to ensure
that we're not missing sibling folds across and/or/xor.
llvm-svn: 301213
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 2259fbaeb98..0f60f1ba8a9 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1877,6 +1877,19 @@ static Value *SimplifyOrInst(Value *Op0, Value *Op1, const Query &Q, (A == Op0 || B == Op0)) return Constant::getAllOnesValue(Op0->getType()); + // (A & ~B) | (A ^ B) -> (A ^ B) + // (~B & A) | (A ^ B) -> (A ^ B) + if (match(Op0, m_c_And(m_Value(A), m_Not(m_Value(B)))) && + match(Op1, m_Xor(m_Specific(A), m_Specific(B)))) + return Op1; + + // 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 Op0; + if (auto *ICILHS = dyn_cast<ICmpInst>(Op0)) { if (auto *ICIRHS = dyn_cast<ICmpInst>(Op1)) { if (Value *V = SimplifyOrOfICmps(ICILHS, ICIRHS)) |