Skip to content

Commit

Permalink
[Reducer] Improve simplification for reducing strategies (#15080)
Browse files Browse the repository at this point in the history
This patch makes the existing reducing strategies produce smaller code.
Without this patch, unused private dispatches are left in the final
output along with other dead code.
  • Loading branch information
Groverkss authored Oct 2, 2023
1 parent 18c7427 commit 868b7fb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,18 @@ void mlir::iree_compiler::Reducer::reduceFlowDispatchOperandToResultDelta(
return;
}

// Replace all dispatch ops with random inputs.
// Replace all dispatch ops with the chosen operand.
for (auto [result, operand] : resultToOperand) {
result.replaceAllUsesWith(operand);
}

// Simplify.
PassManager pm(module.getContext());
pm.addPass(createCanonicalizerPass());
// Dead code eliminate the dispatch ops.
pm.addPass(createCSEPass());
// Dead code eliminate the weights.
pm.addPass(createSymbolDCEPass());
// Canonicalize the module.
pm.addPass(createCanonicalizerPass());
if (failed(pm.run(module))) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,17 @@ void mlir::iree_compiler::Reducer::reduceFlowDispatchResultBySplatDelta(
// Erase the dispatch.
dispatch.erase();
}

PassManager pm(module.getContext());
// Dead code eliminate the dispatch ops.
pm.addPass(createCSEPass());
// Dead code eliminate globals.
pm.addPass(createSymbolDCEPass());
// Canonicalize so that the splats are fused with reshapes.
pm.addPass(createCanonicalizerPass());
// CSE again to de-duplicate splats.
pm.addPass(createCSEPass());
if (failed(pm.run(module))) {
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,12 @@ void mlir::iree_compiler::Reducer::reduceLinalgOnTensorsDelta(
}

PassManager pm(module.getContext());
pm.addPass(createCanonicalizerPass());
// Dead code eliminate.
pm.addPass(createCSEPass());
// De-duplicate identical fills.
pm.addPass(createCanonicalizerPass());
// Remove dead globals.
pm.addPass(createSymbolDCEPass());
if (failed(pm.run(module)))
return;
}

0 comments on commit 868b7fb

Please sign in to comment.