Skip to content

[mlir][linalg] Enhance isaInlinedFillOp #151155

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ bool linalg::isaCopyOpInterface(LinalgOp op) {
/// constant. If so, returns the constant value. Otherwise, returns
/// std::nullopt.
static std::optional<Value> isaInlinedFillOp(GenericOp op) {
if (!op.isAllParallelLoops() || op.getNumDpsInits() != 1 ||
op.getNumDpsInputs() != 0)
if (!op.isAllParallelLoops() || op.getNumDpsInits() != 1)
Copy link
Contributor

@javedabsar1 javedabsar1 Jul 30, 2025

Choose a reason for hiding this comment

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

Actually come to think of it, i wonder why op.getNumDpsInputs() !=0 was there originally, as the input is not read for the fill case -- so why 'isaFilledOpnot checking==0`

return std::nullopt;

// Init should not be referenced.
Expand Down
17 changes: 0 additions & 17 deletions mlir/test/Dialect/Linalg/specialize-generic-ops-fail.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,3 @@ func.func @neither_permutation_nor_broadcast(%init : tensor<8xi32>) -> tensor<8x
} -> tensor<8xi32>
return %res : tensor<8xi32>
}

// -----

#map = affine_map<(d0) -> (d0)>
// CHECK-LABEL: func @not_copy
// CHECK-NOT: linalg.copy
// CHECK: linalg.generic
func.func @not_copy(%input: tensor<8xi32>, %init: tensor<8xi32>) -> tensor<8xi32> {
%c0_i32 = arith.constant 0 : i32
%res = linalg.generic {
indexing_maps = [#map, #map], iterator_types = ["parallel"]
} ins(%input: tensor<8xi32>) outs(%init: tensor<8xi32>) {
^bb0(%in: i32, %out: i32):
linalg.yield %c0_i32 : i32
} -> tensor<8xi32>
return %res : tensor<8xi32>
}
29 changes: 17 additions & 12 deletions mlir/test/Dialect/Linalg/transform-op-specialize.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,15 @@ func.func @linalg_generic_fill(%arg0: tensor<7x7xf32>) -> tensor<7x7xf32> {
} -> tensor<7x7xf32>
return %0 : tensor<7x7xf32>
}

// CHECK-LABEL: linalg_generic_fill
// CHECK-SAME: %[[ARG0:.+]]: tensor<7x7xf32>) -> tensor<7x7xf32>
// CHECK: %[[CST:.+]] = arith.constant 0.000000e+00 : f32
// CHECK: %{{.*}} = linalg.fill ins(%[[CST]] : f32) outs(%[[ARG0]] : tensor<7x7xf32>) -> tensor<7x7xf32>

module attributes {transform.with_named_sequence} {
transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
%0 = transform.structured.match interface{LinalgOp} in %arg1 : (!transform.any_op) -> !transform.any_op
%1 = transform.structured.specialize %0 : (!transform.any_op) -> !transform.any_op
transform.yield
}
}

// -----

#map = affine_map<(d0, d1) -> (d0, d1)>
func.func @linalg_generic_inlined_constant_fill(%arg0: tensor<7x7xf32>) -> tensor<7x7xf32> {
%cst = arith.constant 0.000000e+00 : f32
%0 = linalg.generic {indexing_maps = [#map], iterator_types = ["parallel", "parallel"]} outs(%arg0 : tensor<7x7xf32>) {
%0 = linalg.generic {indexing_maps = [#map1], iterator_types = ["parallel", "parallel"]} outs(%arg0 : tensor<7x7xf32>) {
^bb0(%out: f32):
linalg.yield %cst : f32
} -> tensor<7x7xf32>
Expand All @@ -172,6 +162,21 @@ func.func @linalg_generic_inlined_constant_fill(%arg0: tensor<7x7xf32>) -> tenso
// CHECK: %[[CST:.+]] = arith.constant 0.000000e+00 : f32
// CHECK: %{{.*}} = linalg.fill ins(%[[CST]] : f32) outs(%[[ARG0]] : tensor<7x7xf32>) -> tensor<7x7xf32>

func.func @linalg_generic_inlined_constant_fill_has_input(%input: tensor<8x8xi32>, %init: tensor<8x8xi32>) -> tensor<8x8xi32> {
%c0_i32 = arith.constant 0 : i32
%res = linalg.generic {indexing_maps = [#map1, #map1], iterator_types = ["parallel", "parallel"]} ins(%input: tensor<8x8xi32>) outs(%init: tensor<8x8xi32>) {
^bb0(%in: i32, %out: i32):
linalg.yield %c0_i32 : i32
} -> tensor<8x8xi32>
return %res : tensor<8x8xi32>
}

// CHECK-LABEL: func @linalg_generic_inlined_constant_fill_has_input
// CHECK-SAME: %[[INPUT:.+]]: tensor<8x8xi32>,
// CHECK-SAME: %[[INIT:.+]]: tensor<8x8xi32>) -> tensor<8x8xi32>
// CHECK: %[[CST:.+]] = arith.constant 0 : i32
// CHECK: %{{.*}} = linalg.fill ins(%[[CST]] : i32) outs(%[[INIT]] : tensor<8x8xi32>) -> tensor<8x8xi32>

module attributes {transform.with_named_sequence} {
transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
%0 = transform.structured.match interface{LinalgOp} in %arg1 : (!transform.any_op) -> !transform.any_op
Expand Down