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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Feb 15 14:08:28 PST 2026


================
@@ -784,11 +785,12 @@ struct ValueEquivalenceCache {
     if (lhsIt == lhsRange.end())
       return success();
 
-    // Handle another simple case where operands are just a permutation.
-    // Note: This is not sufficient, this handles simple cases relatively
-    // cheaply.
-    auto sortValues = [](ValueRange values) {
-      SmallVector<Value> sortedValues = llvm::to_vector(values);
+    // Replace values with their entry in equivalentValues if they're in there.
+    // 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); });
----------------
jumerckx wrote:

I've split that part in a pr (on top of my own branch): https://github.com/jumerckx/llvm-project/pull/1

Note that the tests that were originally here are now in the follow up pr because commutative equality does not fully work just by adding the ignore flag.
The test that's now left here just verifies that passing the IgnoreCommutative flag doesn't mess anything up, but even without that flag the operations wouldn't be detected as equivalent without the follow-up pr.

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


More information about the Mlir-commits mailing list