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

Mehdi Amini via flang-commits flang-commits at lists.llvm.org
Wed Dec 13 22:51:25 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();
----------------
joker-eph wrote:

if (!llvm::all_of(llvm::zip(lhsRange, rhsRange), checkEquivalent) return success();`

Edit: oh you're trying to optimize to only sort a subrange?

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


More information about the flang-commits mailing list