[PATCH] D139408: [InstCombine] Fold logic-and/logic-or by distributive laws

Simon Pilgrim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 8 06:07:34 PST 2022


RKSimon added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:2695
+        (CondVal->hasOneUse() || FalseVal->hasOneUse())) {
+      bool CondLogicAnd = isa<SelectInst>(CondVal);
+      bool FalseLogicAnd = isa<SelectInst>(FalseVal);
----------------
lebedev.ri wrote:
> RKSimon wrote:
> > Sorry if I've missed something (looooong day) - but how can this match as a SelectInst if its already matched as m_LogicalAnd above?
> ```
> /// Matches L && R either in the form of L & R or L ? R : false.
> /// Note that the latter form is poison-blocking.
> template <typename LHS, typename RHS>
> inline LogicalOp_match<LHS, RHS, Instruction::And> m_LogicalAnd(const LHS &L,
>                                                                 const RHS &R) {
>   return LogicalOp_match<LHS, RHS, Instruction::And>(L, R);
> }
> 
> /// Matches L && R where L and R are arbitrary values.
> inline auto m_LogicalAnd() { return m_LogicalAnd(m_Value(), m_Value()); }
> 
> ```
Cheers - so what do we gain from matching with m_LogicalAnd first and then checking isa<SelectInst> ?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139408/new/

https://reviews.llvm.org/D139408



More information about the llvm-commits mailing list