[Mlir-commits] [mlir] [mlir] Consolidate two implementations of meet (NFC) (PR #167208)

Kazu Hirata llvmlistbot at llvm.org
Sun Nov 9 08:48:07 PST 2025


https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/167208

>From 155734390304ea57c6bab2ca457b49059fd4536c Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 6 Nov 2025 22:29:38 -0800
Subject: [PATCH 1/2] [mlir] Consolidate two implementations of meet (NFC)

This patch consolidates two implementations of meet using
"if constexpr", migrating away from the SFINAE-based approach.
---
 .../mlir/Analysis/DataFlow/SparseAnalysis.h   | 35 +++++++++----------
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h b/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h
index 985573476ab78..89da84346c109 100644
--- a/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h
+++ b/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h
@@ -138,27 +138,24 @@ class Lattice : public AbstractSparseLattice {
 
   /// Meet (intersect) the information contained in the 'rhs' value with this
   /// lattice. Returns if the state of the current lattice changed.  If the
-  /// lattice elements don't have a `meet` method, this is a no-op (see below.)
-  template <typename VT,
-            std::enable_if_t<lattice_has_meet<VT>::value> * = nullptr>
+  /// lattice elements don't have a `meet` method, this is a no-op.
+  template <typename VT>
   ChangeResult meet(const VT &rhs) {
-    ValueT newValue = ValueT::meet(value, rhs);
-    assert(ValueT::meet(newValue, value) == newValue &&
-           "expected `meet` to be monotonic");
-    assert(ValueT::meet(newValue, rhs) == newValue &&
-           "expected `meet` to be monotonic");
-
-    // Update the current optimistic value if something changed.
-    if (newValue == value)
-      return ChangeResult::NoChange;
-
-    value = newValue;
-    return ChangeResult::Change;
-  }
+    if constexpr (lattice_has_meet<VT>::value) {
+      ValueT newValue = ValueT::meet(value, rhs);
+      assert(ValueT::meet(newValue, value) == newValue &&
+             "expected `meet` to be monotonic");
+      assert(ValueT::meet(newValue, rhs) == newValue &&
+             "expected `meet` to be monotonic");
+
+      // Update the current optimistic value if something changed.
+      if (newValue == value)
+        return ChangeResult::NoChange;
+
+      value = newValue;
+      return ChangeResult::Change;
+    }
 
-  template <typename VT,
-            std::enable_if_t<!lattice_has_meet<VT>::value> * = nullptr>
-  ChangeResult meet(const VT &rhs) {
     return ChangeResult::NoChange;
   }
 

>From 1c5b4572a2292bad272374f1c7d80f76eaa080b3 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 9 Nov 2025 08:46:22 -0800
Subject: [PATCH 2/2] Address a comment.

---
 mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h b/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h
index 89da84346c109..360d3c7e62000 100644
--- a/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h
+++ b/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h
@@ -141,7 +141,9 @@ class Lattice : public AbstractSparseLattice {
   /// lattice elements don't have a `meet` method, this is a no-op.
   template <typename VT>
   ChangeResult meet(const VT &rhs) {
-    if constexpr (lattice_has_meet<VT>::value) {
+    if constexpr (!lattice_has_meet<VT>::value) {
+      return ChangeResult::NoChange;
+    } else {
       ValueT newValue = ValueT::meet(value, rhs);
       assert(ValueT::meet(newValue, value) == newValue &&
              "expected `meet` to be monotonic");
@@ -155,8 +157,6 @@ class Lattice : public AbstractSparseLattice {
       value = newValue;
       return ChangeResult::Change;
     }
-
-    return ChangeResult::NoChange;
   }
 
   /// Print the lattice element.



More information about the Mlir-commits mailing list