Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2507,9 +2507,17 @@ if (Value *V = SimplifyBSwap(I, Builder)) return replaceInstUsesWith(I, V); - // A^B --> A|B iff A and B have no bits set in common. Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); - if (haveNoCommonBitsSet(Op0, Op1, DL, &AC, &I, &DT)) + + // Fold (X & M) ^ (Y & ~M) -> (X & M) | (Y & ~M) + // This it a special case in haveNoCommonBitsSet, but the commputeKnownBits + // calls in there are unnecessary as SimplifyDemandedInstructionBits should + // have already taken care of those cases. + Value *M; + if ((match(Op0, m_c_And(m_Not(m_Value(M)), m_Value())) && + match(Op1, m_c_And(m_Specific(M), m_Value()))) || + (match(Op1, m_c_And(m_Not(m_Value(M)), m_Value())) && + match(Op0, m_c_And(m_Specific(M), m_Value())))) return BinaryOperator::CreateOr(Op0, Op1); // Apply DeMorgan's Law for 'nand' / 'nor' logic with an inverted operand.