From f61de3c1aa8fa4a5fdccbf213e5dca507073d431 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Sun, 18 Dec 2022 22:53:59 +0300 Subject: [PATCH] [NFC][PatternMatching] Promote `m_LogicalOp` matchers into `PatternMatch.h` --- llvm/include/llvm/IR/PatternMatch.h | 19 +++++++++++++++++++ llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 6 +----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h index 9dc8cf9..1027160 100644 --- a/llvm/include/llvm/IR/PatternMatch.h +++ b/llvm/include/llvm/IR/PatternMatch.h @@ -2586,6 +2586,25 @@ m_c_LogicalOr(const LHS &L, const RHS &R) { return LogicalOp_match(L, R); } +/// Matches either L && R or L || R, +/// either one being in the either binary or logical form. +/// Note that the latter form is poison-blocking. +template +inline auto m_LogicalOp(const LHS &L, const RHS &R) { + return m_CombineOr( + LogicalOp_match(L, R), + LogicalOp_match(L, R)); +} + +/// Matches either L && R or L || R where L and R are arbitrary values. +inline auto m_LogicalOp() { return m_LogicalOp(m_Value(), m_Value()); } + +/// Matches either L && R or L || R with LHS and RHS in either order. +template +inline auto m_c_LogicalOp(const LHS &L, const RHS &R) { + return m_LogicalOp(L, R); +} + } // end namespace PatternMatch } // end namespace llvm diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 9fa5bb3..f41909b 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -2712,10 +2712,6 @@ static Instruction *foldNestedSelects(SelectInst &OuterSelVal, if (match(OuterSel.Cond, m_Not(m_Value(OuterSel.Cond)))) std::swap(OuterSel.TrueVal, OuterSel.FalseVal); - auto m_c_LogicalOp = [](auto L, auto R) { - return m_CombineOr(m_c_LogicalAnd(L, R), m_c_LogicalOr(L, R)); - }; - // The condition of the outermost select must be an `and`/`or`. if (!match(OuterSel.Cond, m_c_LogicalOp(m_Value(), m_Value()))) return nullptr; @@ -2741,7 +2737,7 @@ static Instruction *foldNestedSelects(SelectInst &OuterSelVal, std::swap(InnerSel.TrueVal, InnerSel.FalseVal); Value *AltCond = nullptr; - auto matchOuterCond = [OuterSel, m_c_LogicalOp, &AltCond](auto m_InnerCond) { + auto matchOuterCond = [OuterSel, &AltCond](auto m_InnerCond) { return match(OuterSel.Cond, m_c_LogicalOp(m_InnerCond, m_Value(AltCond))); }; -- 2.7.4