diff options
author | Balaram Makam <bmakam@codeaurora.org> | 2015-08-20 15:35:00 +0000 |
---|---|---|
committer | Balaram Makam <bmakam@codeaurora.org> | 2015-08-20 15:35:00 +0000 |
commit | ccf59731e3b7d4920c04339c600ec67af648a9d0 (patch) | |
tree | e905ce1b4789ece1f787c677071e092b51dfa026 /llvm/lib | |
parent | ae6b329c8fcffbd437624111b430e10ad57a7627 (diff) | |
download | bcm5719-llvm-ccf59731e3b7d4920c04339c600ec67af648a9d0.tar.gz bcm5719-llvm-ccf59731e3b7d4920c04339c600ec67af648a9d0.zip |
Optimize bitwise even/odd test (-x&1 -> x&1) to not use negation.
Summary: We know that -x & 1 is equivalent to x & 1, avoid using negation for testing if a negative integer is even or odd.
Reviewers: majnemer
Subscribers: junbuml, mssimpso, gberry, mcrosier, llvm-commits
Differential Revision: http://reviews.llvm.org/D12156
llvm-svn: 245569
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 15e0889b51b..e210c99d126 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -1273,6 +1273,10 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) { if (Value *V = FoldLogicalPlusAnd(Op0LHS, Op0RHS, AndRHS, true, I)) return BinaryOperator::CreateAnd(V, AndRHS); + // -x & 1 -> x & 1 + if (AndRHSMask == 1 && match(Op0LHS, m_Zero())) + return BinaryOperator::CreateAnd(Op0RHS, AndRHS); + // (A - N) & AndRHS -> -N & AndRHS iff A&AndRHS==0 and AndRHS // has 1's for all bits that the subtraction with A might affect. if (Op0I->hasOneUse() && !match(Op0LHS, m_Zero())) { |