@@ -1404,6 +1404,22 @@ class TritonIntelGPURemoveLayoutConversionsPass
14041404 : public intel::impl::TritonIntelGPURemoveLayoutConversionsBase<
14051405 TritonIntelGPURemoveLayoutConversionsPass> {
14061406public:
1407+ // Cleanup convert ops.
1408+ void cleanupConvertOps () {
1409+ MLIRContext *context = &getContext ();
1410+ ModuleOp m = getOperation ();
1411+ RewritePatternSet cleanUpPatterns (context);
1412+ ConvertLayoutOp::getCanonicalizationPatterns (cleanUpPatterns, context);
1413+ if (applyPatternsGreedily (m, std::move (cleanUpPatterns)).failed ()) {
1414+ signalPassFailure ();
1415+ }
1416+
1417+ LLVM_DEBUG ({
1418+ DBGS () << " Module after canonicalizing:\n " ;
1419+ m.dump ();
1420+ });
1421+ }
1422+
14071423 void runOnOperation () override {
14081424 MLIRContext *context = &getContext ();
14091425 ModuleOp m = getOperation ();
@@ -1422,16 +1438,7 @@ class TritonIntelGPURemoveLayoutConversionsPass
14221438 m.dump ();
14231439 });
14241440
1425- RewritePatternSet cleanUpPatterns (context);
1426- ConvertLayoutOp::getCanonicalizationPatterns (cleanUpPatterns, context);
1427- if (applyPatternsGreedily (m, std::move (cleanUpPatterns)).failed ()) {
1428- signalPassFailure ();
1429- }
1430-
1431- LLVM_DEBUG ({
1432- DBGS () << " Module after canonicalizing:\n " ;
1433- m.dump ();
1434- });
1441+ cleanupConvertOps ();
14351442
14361443 // 2. For remaining convert ops, try to rematerialize the slice of producer
14371444 // operation to avoid having to convert.
@@ -1441,6 +1448,9 @@ class TritonIntelGPURemoveLayoutConversionsPass
14411448 m.dump ();
14421449 });
14431450
1451+ // Cleanup dummy converts created during backward remat.
1452+ cleanupConvertOps ();
1453+
14441454 // 3. For remaining converts, try to hoist them above cast generating larger
14451455 // size types in order to reduce the cost of the convert op.
14461456 hoistConvert (m);
0 commit comments