Skip to content

Conversation

etiotto
Copy link
Contributor

@etiotto etiotto commented Aug 18, 2025

This PR implements an optimization to reduce loop carried values in the RemoveLayoutConversions pass by reusing equivalent loop results with layout conversion operations instead of carrying redundant values through loops.

Fixes issue #4901

@etiotto etiotto self-assigned this Aug 18, 2025
@etiotto etiotto requested a review from Copilot August 18, 2025 22:41
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements an optimization to reduce loop carried values in the RemoveLayoutConversions pass by reusing equivalent loop results with layout conversion operations instead of carrying redundant values through loops.

  • Adds logic to identify and replace redundant loop arguments with equivalent ones plus layout conversions
  • Handles LoadOp and StoreOp operations that use these loop results
  • Reduces memory usage and improves loop efficiency by eliminating unnecessary loop-carried tensor pointer values

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
RemoveLayoutConversions.cpp Implements the core optimization logic to reduce loop carried values by replacing redundant arguments with conversions
backward_combine_dpas_dot_layout.mlir Adds test case to verify the optimization works correctly for tensor pointer operations in loops

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@etiotto etiotto changed the title [RemoveLAyoutConversions]: Reduce loop carried values [RemoveLayoutConversions]: Reduce loop carried values Aug 19, 2025
Signed-off-by: Tiotto, Ettore <[email protected]>
@etiotto etiotto marked this pull request as ready for review August 19, 2025 15:16
Comment on lines +1275 to +1278
if (!isa<BlockArgument>(pair.first))
continue;

auto arg = cast<BlockArgument>(pair.first);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!isa<BlockArgument>(pair.first))
continue;
auto arg = cast<BlockArgument>(pair.first);
auto arg = dyn_cast<BlockArgument>(pair.first);
if (!arg)
continue;

Comment on lines +1295 to +1296
for (OpOperand &use : loopRes.getUses()) {
Operation *user = use.getOwner();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Suggested change
for (OpOperand &use : loopRes.getUses()) {
Operation *user = use.getOwner();
for (Operation *user : loopRes.getUsers()) {

Comment on lines +381 to +383
%24 = arith.truncf %23#0 : tensor<64x256xf32, #dpas> to tensor<64x256xf16, #dpas>
%27 = tt.make_tensor_ptr %arg2, [%c0_i64, %c0_i64], [%c0_i64, %c1_i64], [%c0_i32, %c0_i32] {order = array<i32: 1, 0>} : <tensor<64x256xf16, #dpas>>
tt.store %27, %24 {boundaryCheck = array<i32: 0, 1>} : !tt.ptr<tensor<64x256xf16, #dpas>>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like these 3 lines can be removed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RemoveLayoutConversions]: Rematerialization increases loop carried values in loop
2 participants