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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Nov 8 23:57:36 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

This patch consolidates two implementations of meet using
"if constexpr", migrating away from the SFINAE-based approach.


---
Full diff: https://github.com/llvm/llvm-project/pull/167208.diff


1 Files Affected:

- (modified) mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h (+16-19) 


``````````diff
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;
   }
 

``````````

</details>


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


More information about the Mlir-commits mailing list