[Mlir-commits] [mlir] [mlir][amdgpu] Fuse adjacent `MemoryCounterWaitOp` (PR #171148)
Ivan Butygin
llvmlistbot at llvm.org
Mon Dec 8 07:39:37 PST 2025
================
@@ -596,6 +596,51 @@ LogicalResult PermlaneSwapOp::verify() {
return success();
}
+//===----------------------------------------------------------------------===//
+// MemoryCounterWaitOp
+//===----------------------------------------------------------------------===//
+
+namespace {
+/// Fuse adjacent memory counter wait ops, taking the minimum value of the
+/// counters.
+struct FuseMemoryCounterWaitOp final : OpRewritePattern<MemoryCounterWaitOp> {
+ using Base::Base;
+
+ LogicalResult matchAndRewrite(MemoryCounterWaitOp op,
+ PatternRewriter &rewriter) const override {
+ auto next = dyn_cast<MemoryCounterWaitOp>(op->getNextNode());
+ if (!next)
+ return failure();
+
+ auto setters = {&MemoryCounterWaitOp::setLoad,
+ &MemoryCounterWaitOp::setStore, &MemoryCounterWaitOp::setDs,
+ &MemoryCounterWaitOp::setExp};
+ auto lhsVals = {op.getLoad(), op.getStore(), op.getDs(), op.getExp()};
+ auto rhsVals = {next.getLoad(), next.getStore(), next.getDs(),
+ next.getExp()};
+ rewriter.modifyOpInPlace(op, [&] {
+ for (auto [setter, lhs, rhs] :
+ llvm::zip_equal(setters, lhsVals, rhsVals)) {
+ if (lhs && rhs) {
+ (op.*setter)(std::min(*lhs, *rhs));
+ } else if (lhs) {
+ (op.*setter)(*lhs);
+ } else if (rhs) {
+ (op.*setter)(*rhs);
+ }
----------------
Hardcode84 wrote:
should be now
https://github.com/llvm/llvm-project/pull/171148
More information about the Mlir-commits
mailing list