Skip to content

[mlir][LICM] Restrict LICM to pure tensor semantics #129673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions mlir/lib/Transforms/Utils/LoopInvariantCodeMotionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,11 @@ MatchingSubsets::populateSubsetOpsAtIterArg(LoopLikeOpInterface loopLike,
if (auto insertionOp =
dyn_cast<SubsetInsertionOpInterface>(use.getOwner())) {
// Current implementation expects that the insertionOp implement
// the destinationStyleOpInterface as well. Abort if that tha is not
// the case
if (!isa<DestinationStyleOpInterface>(use.getOwner())) {
// the DestinationStyleOpInterface and with pure tensor semantics
// as well. Abort if that is not the case.
auto dstOp = dyn_cast<DestinationStyleOpInterface>(use.getOwner());
if (!dstOp || !dstOp.hasPureTensorSemantics())
return failure();
}

// The value must be used as a destination. (In case of a source, the
// entire tensor would be read, which would prevent any hoisting.)
Expand Down
18 changes: 18 additions & 0 deletions mlir/test/Transforms/loop-invariant-subset-hoisting.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,21 @@ func.func @hoist_vector_transfer_write_pairs_disjoint_tensor(
}
return %1 : tensor<?x?xf32>
}

// -----

// Ensure that cases with buffer semantics exit gracefully.

// CHECK-LABEL: @hoist_buffer
func.func @hoist_buffer(%arg0: memref<7x7xf16>) {
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%alloc = memref.alloc() : memref<7x7xf16>
// CHECK: scf.for
// CHECK: linalg.copy
%0 = scf.for %arg1 = %c0 to %c1 step %c1 iter_args(%arg2 = %alloc) -> (memref<7x7xf16>) {
linalg.copy ins(%arg0 : memref<7x7xf16>) outs(%arg2 : memref<7x7xf16>)
scf.yield %alloc : memref<7x7xf16>
}
return
}