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

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 24 04:51:25 PDT 2018


lebedev.ri added inline comments.


================
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();
----------------
dnsampaio wrote:
> 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);
> ```
> 
> 
See `m_CombineAnd()`


https://reviews.llvm.org/D49229





More information about the llvm-commits mailing list