[PATCH] D49229: [InstCombine] Fold redundant masking operations of shifted value

Diogo N. Sampaio via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 24 04:50:05 PDT 2018


dnsampaio marked 13 inline comments as done.
dnsampaio added a comment.

Did most fixes. Just don't how to capture non-leaf nodes of the pattern being matched. Using other match operations would actually be more complicated than just passing the operands as arguments to the new function, now that I already know they are AND operations due the function call placement.



================
Comment at: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:2053-2058
+      BinaryOperator *And = cast<BinaryOperator>(I.getOperand(1));
+      BinaryOperator *ShtAnd = cast<BinaryOperator>(I.getOperand(0));
+      BinaryOperator *Shift = cast<BinaryOperator>(
+          isa<BinaryOperator>(ShtAnd->getOperand(0)) ? ShtAnd->getOperand(0)
+                                                     : ShtAnd->getOperand(1));
+      const Instruction::BinaryOps Opcode = Shift->getOpcode();
----------------
lebedev.ri wrote:
> Capture them in `match()`.
I don't see how to capture nodes that are not the leafs of the pattern. Should I use another match? It would be easier to just check if the first operand of the OR is the "and(X, AndC)" no?
```
if (match(&I, m_c_Or(m_And(m_OneUse(m_Shift(m_Value(X),
            m_APInt(ShftAmt))), m_APInt(ShAndC)),m_And(
            m_Deferred(X),  m_APInt(AndC))))){
 BinaryOperator *And = I.getOperand(0), *ShtAnd = I.getOperand(1), *Shift;
if(And->getOperand(0) != X)
 std::swap(And, ShtAnd);
Shift = ShtAnd->getOperand(0);
```




https://reviews.llvm.org/D49229





More information about the llvm-commits mailing list