[llvm] [DAG] SDPatternMatch::ReassociatableOpc_match - pull out repeated pattern count expression. NFC. (PR #135187)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 10 07:34:04 PDT 2025


https://github.com/RKSimon created https://github.com/llvm/llvm-project/pull/135187

Minor tidyup to remove so much template noise.

CC @esan5

>From 58d4f599c75fc9aac6c9dd2c91f4c3c6ea5db73b Mon Sep 17 00:00:00 2001
From: Simon Pilgrim <llvm-dev at redking.me.uk>
Date: Thu, 10 Apr 2025 15:32:49 +0100
Subject: [PATCH] [DAG] SDPatternMatch::ReassociatableOpc_match - pull out
 repeated pattern count expression. NFC.

Minor tidyup
---
 llvm/include/llvm/CodeGen/SDPatternMatch.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/llvm/include/llvm/CodeGen/SDPatternMatch.h b/llvm/include/llvm/CodeGen/SDPatternMatch.h
index 4e1e4fdccfea5..9532be67c92e1 100644
--- a/llvm/include/llvm/CodeGen/SDPatternMatch.h
+++ b/llvm/include/llvm/CodeGen/SDPatternMatch.h
@@ -1145,16 +1145,17 @@ template <typename... PatternTs> struct ReassociatableOpc_match {
 
   template <typename MatchContext>
   bool match(const MatchContext &Ctx, SDValue N) {
+    constexpr size_t NumPatterns = std::tuple_size_v<std::tuple<PatternTs...>>;
+
     SmallVector<SDValue> Leaves;
     collectLeaves(N, Leaves);
-    if (Leaves.size() != std::tuple_size_v<std::tuple<PatternTs...>>)
+    if (Leaves.size() != NumPatterns)
       return false;
 
     // Matches[I][J] == true iff sd_context_match(Leaves[I], Ctx,
     // std::get<J>(Patterns)) == true
-    std::array<SmallBitVector, std::tuple_size_v<std::tuple<PatternTs...>>>
-        Matches;
-    for (size_t I = 0, N = Leaves.size(); I < N; I++) {
+    std::array<SmallBitVector, NumPatterns> Matches;
+    for (size_t I = 0; I != NumPatterns; I++) {
       SmallVector<bool> MatchResults;
       std::apply(
           [&](auto &...P) {
@@ -1163,7 +1164,7 @@ template <typename... PatternTs> struct ReassociatableOpc_match {
           Patterns);
     }
 
-    SmallBitVector Used(std::tuple_size_v<std::tuple<PatternTs...>>);
+    SmallBitVector Used(NumPatterns);
     return reassociatableMatchHelper(Matches, Used);
   }
 



More information about the llvm-commits mailing list