[Mlir-commits] [mlir] [mlir] Add option to ignore commutativity in OperationEquality (PR #181507)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Feb 14 12:53:51 PST 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- mlir/include/mlir/IR/OperationSupport.h mlir/lib/IR/OperationSupport.cpp mlir/test/lib/IR/TestOperationEquals.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h
index 9aab65b6f..3b79f2635 100644
--- a/mlir/include/mlir/IR/OperationSupport.h
+++ b/mlir/include/mlir/IR/OperationSupport.h
@@ -1331,8 +1331,8 @@ struct OperationEquivalence {
     // When provided, the properties attached to the operation are ignored.
     IgnoreProperties = 4,
 
-    // When provided, the commutativity of the operation is ignored, and operands
-    // are compared in an order-sensitive way.
+    // When provided, the commutativity of the operation is ignored, and
+    // operands are compared in an order-sensitive way.
     IgnoreCommutativity = 8,
 
     LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ IgnoreCommutativity)
diff --git a/mlir/lib/IR/OperationSupport.cpp b/mlir/lib/IR/OperationSupport.cpp
index a7a67744b..309b7c730 100644
--- a/mlir/lib/IR/OperationSupport.cpp
+++ b/mlir/lib/IR/OperationSupport.cpp
@@ -786,11 +786,11 @@ struct ValueEquivalenceCache {
       return success();
 
     // Replace values with their entry in equivalentValues if they're in there
-    // that way, a sorted pointer comparison is enough to determine commutativity.
+    // that way, a sorted pointer comparison is enough to determine
+    // commutativity.
     auto sortValues = [this](ValueRange values) {
-      SmallVector<Value> sortedValues = llvm::map_to_vector(values, [this](Value a) {
-          return equivalentValues.lookup_or(a, a);
-      });
+      SmallVector<Value> sortedValues = llvm::map_to_vector(
+          values, [this](Value a) { return equivalentValues.lookup_or(a, a); });
       llvm::sort(sortedValues, [](Value a, Value b) {
         return a.getAsOpaquePointer() < b.getAsOpaquePointer();
       });
@@ -799,7 +799,7 @@ struct ValueEquivalenceCache {
     auto lhsSorted = sortValues({lhsIt, lhsRange.end()});
     auto rhsSorted = sortValues({rhsIt, rhsRange.end()});
     if (lhsSorted == rhsSorted) {
-        return success();
+      return success();
     }
     return failure();
   }
@@ -859,8 +859,7 @@ OperationEquivalence::isRegionEquivalentTo(Region *lhs, Region *rhs,
     return false;
 
   // 2. Compare operands.
-  if (!(flags & IgnoreCommutativity) &&
-      checkCommutativeEquivalent &&
+  if (!(flags & IgnoreCommutativity) && checkCommutativeEquivalent &&
       lhs->hasTrait<mlir::OpTrait::IsCommutative>()) {
     auto lhsRange = lhs->getOperands();
     auto rhsRange = rhs->getOperands();
@@ -892,9 +891,9 @@ OperationEquivalence::isRegionEquivalentTo(Region *lhs, Region *rhs,
 
   // 4. Compare regions.
   for (auto regionPair : llvm::zip(lhs->getRegions(), rhs->getRegions()))
-    if (!isRegionEquivalentTo(&std::get<0>(regionPair),
-                              &std::get<1>(regionPair), checkEquivalent,
-                              markEquivalent, flags, checkCommutativeEquivalent))
+    if (!isRegionEquivalentTo(
+            &std::get<0>(regionPair), &std::get<1>(regionPair), checkEquivalent,
+            markEquivalent, flags, checkCommutativeEquivalent))
       return false;
 
   return true;

``````````

</details>


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


More information about the Mlir-commits mailing list