[flang-commits] [flang] [mlir] [mlir] Handle simple commutative cases in CSE. (PR #75274)

Jacques Pienaar via flang-commits flang-commits at lists.llvm.org
Thu Dec 14 09:39:37 PST 2023


================
@@ -751,6 +763,36 @@ struct ValueEquivalenceCache {
     return success(lhsValue == rhsValue ||
                    equivalentValues.lookup(lhsValue) == rhsValue);
   }
+  LogicalResult checkCommutativeEquivalent(ValueRange lhsRange,
+                                           ValueRange rhsRange) {
+    // Handle simple case where sizes mismatch.
+    if (lhsRange.size() != rhsRange.size())
+      return failure();
+
+    // Handle where operands in order are equivalent.
+    auto lhsIt = lhsRange.begin();
+    auto rhsIt = rhsRange.begin();
+    for (; lhsIt != lhsRange.end(); ++lhsIt, ++rhsIt) {
+      if (failed(checkEquivalent(*lhsIt, *rhsIt)))
+        break;
+    }
+    if (lhsIt == lhsRange.end())
+      return success();
----------------
jpienaar wrote:

Well, more I'm trying to avoid sorting. So once commutative is handled as presort somewhere, it would just be the above/commutative would not be special here. And the sorted side I'm not considering equivalence classes there, its pure Value comparison rather than querying `equivalentValues` map too. That's as mentioned in PR description to keep this rather minimal.

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


More information about the flang-commits mailing list