Add following fold opportunity:
((A | B) ^ A ) & ((A | B) ^ B) --> 0
Differential D115755
[InstSimplify] Fold logic And to Zero MehrHeidar on Dec 14 2021, 1:08 PM. Authored by
Details
Add following fold opportunity: ((A | B) ^ A ) & ((A | B) ^ B) --> 0
Diff Detail
Event Timeline
Comment Actions There are still 2 comments around tests.
Comment Actions The code seems more complicated than necessary (and the tests less thorough than necessary). BinaryOperator *Or; if (match(Op0, m_c_Xor(m_Value(X), m_BinOp(Or)))) if (match(Or, m_c_Or(m_Specific(X), m_Value(Y))) && match(Op1, m_c_Xor(m_Specific(Or), m_Specific(Y)))) return Constant::getNullValue(Op0->getType()); Comment Actions On 2nd thought, that might not be complicated enough. :) BinaryOperator *Or; if (match(Op0, m_c_Xor(m_Value(X), m_CombineAnd(m_BinOp(Or), m_c_Or(m_Deferred(X), m_Value(Y))))) && match(Op1, m_c_Xor(m_Specific(Or), m_Specific(Y)))) return Constant::getNullValue(Op0->getType()); Comment Actions Thank you! %or1 = or i32 %y, %x %or2 = or i32 %x, %y %xor1 = xor i32 %y, %or1 %xor2 = xor i32 %or2, %x %and = and i32 %xor1, %xor2 ret i32 %and Comment Actions Unless we have some evidence that this pattern can escape a typical -O1 pipeline, I don't think we need to care about it. %or1 and %or2 should be CSE'd independently of instsimplify. In other words, I think the positive tests only need to include a single 'or' instruction. If you want to include a test with different 'or' instructions to show the limits of instsimplify, that's fine. Comment Actions Thank you for explaining the reason behind this. I checked the test case and it did get simplified and we ended up with a single or; So I updated the code and test cases.
|
Could you please use X and Y in the comment, same as in the match?