[flang-commits] [mlir] [flang] [mlir] Handle simple commutative cases in CSE. (PR #75274)
Jacques Pienaar via flang-commits
flang-commits at lists.llvm.org
Wed Dec 13 21:05:34 PST 2023
================
@@ -798,15 +844,24 @@ OperationEquivalence::isRegionEquivalentTo(Region *lhs, Region *rhs,
return false;
// 2. Compare operands.
- for (auto operandPair : llvm::zip(lhs->getOperands(), rhs->getOperands())) {
- Value curArg = std::get<0>(operandPair);
- Value otherArg = std::get<1>(operandPair);
- if (curArg == otherArg)
- continue;
- if (curArg.getType() != otherArg.getType())
- return false;
- if (failed(checkEquivalent(curArg, otherArg)))
+ if (checkCommutativeEquivalent &&
+ lhs->hasTrait<mlir::OpTrait::IsCommutative>()) {
+ auto lhsRange = lhs->getOperands();
+ auto rhsRange = rhs->getOperands();
+ if (failed(checkCommutativeEquivalent(lhsRange, rhsRange)))
----------------
jpienaar wrote:
We could, but this is O(n^2) vs O(n log n). Now, this should be replaced by the explicit commutative sort pass in pipeline so that here it should suffice to just do the linear scan. The default param means its easy to drop again at that point without needing to update.
https://github.com/llvm/llvm-project/pull/75274
More information about the flang-commits
mailing list