[Mlir-commits] [mlir] [mlir] Clean up equality comparisons (NFC) (PR #237130)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Oct 30 00:49:28 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Yi-Chi Lee (yichi170)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/237130.diff
3 Files Affected:
- (modified) mlir/include/mlir/Interfaces/InferTypeOpInterface.td (+1-1)
- (modified) mlir/test/lib/Analysis/DataFlow/TestSparseBackwardDataFlowAnalysis.cpp (+1-1)
- (modified) mlir/unittests/IR/OpPropertiesTest.cpp (+1-1)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/237130
More information about the Mlir-commits
mailing list