Optimize bitwise even/odd test (-x&1 -> x&1) to not use negation.
[oota-llvm.git] / lib / Transforms / InstCombine / InstCombineAndOrXor.cpp
index 15e0889b51b75b4430e971d64e076195fbd4427d..e210c99d126381771359c2a2591aaed767ce80b8 100644 (file)
@@ -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())) {