[llvm] Add m_SelectCCLike matcher to match SELECT_CC or SELECT with SETCC (PR #149646)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 19 01:40:30 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- llvm/include/llvm/CodeGen/SDPatternMatch.h llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/include/llvm/CodeGen/SDPatternMatch.h b/llvm/include/llvm/CodeGen/SDPatternMatch.h
index aeafb4f6d..6d77c0576 100644
--- a/llvm/include/llvm/CodeGen/SDPatternMatch.h
+++ b/llvm/include/llvm/CodeGen/SDPatternMatch.h
@@ -93,7 +93,8 @@ struct Value_match {
explicit Value_match(SDValue Match) : MatchVal(Match) {}
- template <typename MatchContext> bool match(const MatchContext &, SDValue N) const {
+ template <typename MatchContext>
+ bool match(const MatchContext &, SDValue N) const {
if (MatchVal)
return MatchVal == N;
return N.getNode();
@@ -130,7 +131,8 @@ struct DeferredValue_match {
explicit DeferredValue_match(SDValue &Match) : MatchVal(Match) {}
- template <typename MatchContext> bool match(const MatchContext &, SDValue N) const {
+ template <typename MatchContext>
+ bool match(const MatchContext &, SDValue N) const {
return N == MatchVal;
}
};
@@ -196,7 +198,8 @@ struct Value_bind {
explicit Value_bind(SDValue &N) : BindVal(N) {}
- template <typename MatchContext> bool match(const MatchContext &, SDValue N) const {
+ template <typename MatchContext>
+ bool match(const MatchContext &, SDValue N) const {
BindVal = N;
return true;
}
@@ -1203,7 +1206,8 @@ struct CondCode_match {
explicit CondCode_match(ISD::CondCode *CC) : BindCC(CC) {}
- template <typename MatchContext> bool match(const MatchContext &, SDValue N) const {
+ template <typename MatchContext>
+ bool match(const MatchContext &, SDValue N) const {
if (auto *CC = dyn_cast<CondCodeSDNode>(N.getNode())) {
if (CCToMatch && *CCToMatch != CC->get())
return false;
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 5acc3a23a..f7f0fb01f 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -265,46 +265,47 @@ namespace {
MaximumLegalStoreInBits = VT.getSizeInBits().getKnownMinValue();
}
- template <typename LTy, typename RTy, typename TTy, typename FTy,
- typename CCTy>
- struct SelectCC_match {
- LTy L;
- RTy R;
- TTy T;
- FTy F;
- CCTy CC;
-
- SelectCC_match(LTy L, RTy R, TTy T, FTy F, CCTy CC)
- : L(std::move(L)), R(std::move(R)), T(std::move(T)), F(std::move(F)),
- CC(std::move(CC)) {}
-
- template <typename MatchContext>
- bool match(const MatchContext &Ctx, SDValue V) const {
- return V.getOpcode() == ISD::SELECT_CC && L.match(Ctx, V.getOperand(0)) &&
- R.match(Ctx, V.getOperand(1)) && T.match(Ctx, V.getOperand(2)) &&
- F.match(Ctx, V.getOperand(3)) && CC.match(Ctx, V.getOperand(4));
- }
- };
-
- template <typename LTy, typename RTy, typename TTy, typename FTy,
- typename CCTy>
- inline auto m_SelectCC(LTy &&L, RTy &&R, TTy &&T, FTy &&F, CCTy &&CC) {
- return SelectCC_match<std::decay_t<LTy>, std::decay_t<RTy>,
- std::decay_t<TTy>, std::decay_t<FTy>,
- std::decay_t<CCTy>>(
- std::forward<LTy>(L), std::forward<RTy>(R), std::forward<TTy>(T),
- std::forward<FTy>(F), std::forward<CCTy>(CC));
- }
-
- template <typename LTy, typename RTy, typename TTy, typename FTy,
- typename CCTy>
- inline auto m_SelectCCLike(LTy &&L, RTy &&R, TTy &&T, FTy &&F, CCTy &&CC) {
- return SDPatternMatch::m_AnyOf(
- SDPatternMatch::m_Select(SDPatternMatch::m_SetCC(L, R, CC), T, F),
- m_SelectCC(std::forward<LTy>(L), std::forward<RTy>(R),
- std::forward<TTy>(T), std::forward<FTy>(F),
- std::forward<CCTy>(CC)));
- }
+ template <typename LTy, typename RTy, typename TTy, typename FTy,
+ typename CCTy>
+ struct SelectCC_match {
+ LTy L;
+ RTy R;
+ TTy T;
+ FTy F;
+ CCTy CC;
+
+ SelectCC_match(LTy L, RTy R, TTy T, FTy F, CCTy CC)
+ : L(std::move(L)), R(std::move(R)), T(std::move(T)), F(std::move(F)),
+ CC(std::move(CC)) {}
+
+ template <typename MatchContext>
+ bool match(const MatchContext &Ctx, SDValue V) const {
+ return V.getOpcode() == ISD::SELECT_CC &&
+ L.match(Ctx, V.getOperand(0)) && R.match(Ctx, V.getOperand(1)) &&
+ T.match(Ctx, V.getOperand(2)) && F.match(Ctx, V.getOperand(3)) &&
+ CC.match(Ctx, V.getOperand(4));
+ }
+ };
+
+ template <typename LTy, typename RTy, typename TTy, typename FTy,
+ typename CCTy>
+ inline auto m_SelectCC(LTy &&L, RTy &&R, TTy &&T, FTy &&F, CCTy &&CC) {
+ return SelectCC_match<std::decay_t<LTy>, std::decay_t<RTy>,
+ std::decay_t<TTy>, std::decay_t<FTy>,
+ std::decay_t<CCTy>>(
+ std::forward<LTy>(L), std::forward<RTy>(R), std::forward<TTy>(T),
+ std::forward<FTy>(F), std::forward<CCTy>(CC));
+ }
+
+ template <typename LTy, typename RTy, typename TTy, typename FTy,
+ typename CCTy>
+ inline auto m_SelectCCLike(LTy &&L, RTy &&R, TTy &&T, FTy &&F, CCTy &&CC) {
+ return SDPatternMatch::m_AnyOf(
+ SDPatternMatch::m_Select(SDPatternMatch::m_SetCC(L, R, CC), T, F),
+ m_SelectCC(std::forward<LTy>(L), std::forward<RTy>(R),
+ std::forward<TTy>(T), std::forward<FTy>(F),
+ std::forward<CCTy>(CC)));
+ }
void ConsiderForPruning(SDNode *N) {
// Mark this for potential pruning.
@@ -4143,8 +4144,9 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
if (sd_match(N1, m_SelectCCLike(m_Specific(N0), m_Value(Y), m_Zero(),
m_Deferred(Y),
m_SpecificCondCode(ISD::SETULT))) ||
- sd_match(N1, m_SelectCCLike(m_Specific(N0), m_Value(Y), m_Deferred(Y),
- m_Zero(), m_SpecificCondCode(ISD::SETUGE)))||
+ sd_match(N1,
+ m_SelectCCLike(m_Specific(N0), m_Value(Y), m_Deferred(Y),
+ m_Zero(), m_SpecificCondCode(ISD::SETUGE))) ||
sd_match(N1, m_VSelect(m_SetCC(m_Specific(N0), m_Value(Y),
m_SpecificCondCode(ISD::SETULT)),
m_Zero(), m_Deferred(Y))) ||
``````````
</details>
https://github.com/llvm/llvm-project/pull/149646
More information about the llvm-commits
mailing list