Skip to content

Commit

Permalink
[BACKEND] Cleanup IR after backward remat in RemoveLayoutConversions (#…
Browse files Browse the repository at this point in the history
…5659)

Backward remat creates a lot of dummy convert ops that should be removed
before running the hosting phase otherwise we spend a lot of time
looking at dummy convert.

This doesn't change the result of the pass but it helps reduce compile
time and prevent combinatory explosion.
  • Loading branch information
ThomasRaoux authored Jan 21, 2025
1 parent febe2a1 commit 03b40df
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions lib/Dialect/TritonGPU/Transforms/RemoveLayoutConversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,22 @@ class TritonGPURemoveLayoutConversionsPass
: public impl::TritonGPURemoveLayoutConversionsBase<
TritonGPURemoveLayoutConversionsPass> {
public:
// Cleanup convert ops.
void cleanupConvertOps() {
MLIRContext *context = &getContext();
ModuleOp m = getOperation();
RewritePatternSet cleanUpPatterns(context);
ConvertLayoutOp::getCanonicalizationPatterns(cleanUpPatterns, context);
if (applyPatternsAndFoldGreedily(m, std::move(cleanUpPatterns)).failed()) {
signalPassFailure();
}

LLVM_DEBUG({
DBGS() << "Module after canonicalizing:\n";
m.dump();
});
}

void runOnOperation() override {
MLIRContext *context = &getContext();
ModuleOp m = getOperation();
Expand All @@ -1191,16 +1207,7 @@ class TritonGPURemoveLayoutConversionsPass
m.dump();
});

RewritePatternSet cleanUpPatterns(context);
ConvertLayoutOp::getCanonicalizationPatterns(cleanUpPatterns, context);
if (applyPatternsAndFoldGreedily(m, std::move(cleanUpPatterns)).failed()) {
signalPassFailure();
}

LLVM_DEBUG({
DBGS() << "Module after canonicalizing:\n";
m.dump();
});
cleanupConvertOps();

// 2. For remaining convert ops, try to rematerialize the slice of producer
// operation to avoid having to convert.
Expand All @@ -1210,6 +1217,9 @@ class TritonGPURemoveLayoutConversionsPass
m.dump();
});

// Cleanup dummy converts created during backward remat.
cleanupConvertOps();

// 3. For remaining converts, try to hoist them above cast generating larger
// size types in order to reduce the cost of the convert op.
hoistConvert(m);
Expand Down

0 comments on commit 03b40df

Please sign in to comment.