[Mlir-commits] [mlir] [mlir] Clean up equality comparisons (NFC) (PR #237130)
Yi-Chi Lee
llvmlistbot at llvm.org
Fri Oct 30 00:48:49 PDT 2026
https://github.com/yichi170 created https://github.com/llvm/llvm-project/pull/237130
Improve equality comparisons in MLIR:
* Use `llvm::equal` for comparing `TypeRange` values in `InferTypeOpInterface`.
* Make `WrittenToLatticeValue::operator==` const-qualified.
* Make both parameters of `TestProperties::operator==` const-qualified.
These changes clarify comparison semantics, improve const-correctness, and resolve ambiguous equality operator overloads under C++20 while preserving C++17 compatibility and existing behavior.
>From 7a302791cd0cfaeb8df1138aa6bba32ebd961bf6 Mon Sep 17 00:00:00 2001
From: yichi170 <yichi170 at gmail.com>
Date: Fri, 30 Oct 2026 00:39:30 -0700
Subject: [PATCH] [mlir] Clean up equality comparisons (NFC)
This patch makes several small improvements to equality comparisons in MLIR:
Use llvm::equal for comparing TypeRange values in InferTypeOpInterface.
Make WrittenToLatticeValue::operator== const-qualified.
Make both parameters of TestProperties::operator== const-qualified.
These changes clarify comparison semantics and improve const-correctness without changing the intended behavior.
---
mlir/include/mlir/Interfaces/InferTypeOpInterface.td | 2 +-
.../Analysis/DataFlow/TestSparseBackwardDataFlowAnalysis.cpp | 2 +-
mlir/unittests/IR/OpPropertiesTest.cpp | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/mlir/include/mlir/Interfaces/InferTypeOpInterface.td b/mlir/include/mlir/Interfaces/InferTypeOpInterface.td
index 36397d596aed6c..b408e34b11e684 100644
--- a/mlir/include/mlir/Interfaces/InferTypeOpInterface.td
+++ b/mlir/include/mlir/Interfaces/InferTypeOpInterface.td
@@ -119,7 +119,7 @@ def InferTypeOpInterface : OpInterface<"InferTypeOpInterface"> {
/*defaultImplementation=*/[{
/// Returns whether two arrays are equal as strongest check for
/// compatibility by default.
- return lhs == rhs;
+ return llvm::equal(lhs, rhs);
}]
>,
];
diff --git a/mlir/test/lib/Analysis/DataFlow/TestSparseBackwardDataFlowAnalysis.cpp b/mlir/test/lib/Analysis/DataFlow/TestSparseBackwardDataFlowAnalysis.cpp
index 18c74093e518f8..b4e1953abc2090 100644
--- a/mlir/test/lib/Analysis/DataFlow/TestSparseBackwardDataFlowAnalysis.cpp
+++ b/mlir/test/lib/Analysis/DataFlow/TestSparseBackwardDataFlowAnalysis.cpp
@@ -20,7 +20,7 @@ namespace {
/// Lattice value storing the a set of memory resources that something
/// is written to.
struct WrittenToLatticeValue {
- bool operator==(const WrittenToLatticeValue &other) {
+ bool operator==(const WrittenToLatticeValue &other) const {
return this->writes == other.writes;
}
diff --git a/mlir/unittests/IR/OpPropertiesTest.cpp b/mlir/unittests/IR/OpPropertiesTest.cpp
index ba966bfdc28ca7..b433f5bc13490c 100644
--- a/mlir/unittests/IR/OpPropertiesTest.cpp
+++ b/mlir/unittests/IR/OpPropertiesTest.cpp
@@ -30,7 +30,7 @@ struct TestProperties {
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestProperties)
};
-bool operator==(const TestProperties &lhs, TestProperties &rhs) {
+bool operator==(const TestProperties &lhs, const TestProperties &rhs) {
return lhs.a == rhs.a && lhs.b == rhs.b && lhs.array == rhs.array &&
lhs.label == rhs.label;
}
More information about the Mlir-commits
mailing list