[LLVMCPU] Tile fills to vector sizes like other ops (#25255) ## Context We have inconsistent handling of named linalg operations v.s. generics. Ideally it should not matter in which form we see the operation, in all cases we should handle the same way if it is semantically identical. The usage of `llvm::isa` can prevent this in later stages of the pipeline, thus it is preferable to avoid checks on the type and rather use the op interface instead e.g. `linalg::isaConvolutionOpInterface` ## This PR `LLVMCPUTileToVectorSizePass` skipped every `linalg.fill`, on the assumption that a fill has already been tiled together with its consumer. An equivalent `linalg.generic` fill did not get the exemption, so the two forms were handled differently: a named 16x16 fill with vector sizes `[4, 4]` was left alone, its generalized form got two loops. The pass already leaves an op alone when its dimensions are not larger than the vector sizes, or not statically known. That is the situation of a fill that was tiled with its consumer, so the exemption looks redundant. This PR removes it; a fill then goes through the same check as every other op. ## Effect on `iree-compile` I compared the compiled modules before and after, byte for byte: | Programs | Target | Compiled | Identical | |---|---|---:|---:| | 103 single-op programs (convolutions, poolings, contractions, attention, pad, reductions, QDQ variants), default flags and data tiling + ukernels | Apple M4 host | 204 | 204 | | `tests/e2e/**/*.mlir`, same two flag sets | Apple M4 host | 403 | 401 | | | RISC-V 64, `spacemit-x60` | 403 | 403 | | | x86-64, `skylake-avx512` | 403 | 403 | The two differing modules are `stablehlo_models/mnist_fake_weights` in both flag sets. That program does not compile deterministically on `main` on this host: repeated runs of the same compiler alternate between two outputs, so it says nothing about this change. 7 further e2e files do not compile standalone with these flags on either side. So I found no program where the exemption changes the generated code. If there is a case where a fill reaches this pass larger than its vector sizes and should stay untiled, I have not been able to construct it; pointers welcome. ## Tests `tile_to_vector_size.mlir` gets a fill that is larger than its vector sizes and is now tiled. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Florian Walbroel <walbroel@roofline.ai> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
diff --git a/compiler/src/iree/compiler/Codegen/LLVMCPU/LLVMCPUTileToVectorSize.cpp b/compiler/src/iree/compiler/Codegen/LLVMCPU/LLVMCPUTileToVectorSize.cpp index de24869..000d8ed 100644 --- a/compiler/src/iree/compiler/Codegen/LLVMCPU/LLVMCPUTileToVectorSize.cpp +++ b/compiler/src/iree/compiler/Codegen/LLVMCPU/LLVMCPUTileToVectorSize.cpp
@@ -129,13 +129,6 @@ FunctionOpInterface funcOp = getOperation(); SmallVector<linalg::LinalgOp> candidates; funcOp.walk([&](linalg::LinalgOp op) { - // XXX(hanchung): linalg.fill usually follow the reduction consumer ops, so - // the additional tiling is not needed. Otherwise, it results in an - // additional loops before converting it to a vector. We may need to fix the - // lowering config issue, but it is a fair stopgap in practice. - if (isa<linalg::FillOp>(op)) { - return; - } IREE::Codegen::LoweringConfigAttrInterface loweringConfig = getLoweringConfig(op); if (!loweringConfig) {
diff --git a/compiler/src/iree/compiler/Codegen/LLVMCPU/test/tile_to_vector_size.mlir b/compiler/src/iree/compiler/Codegen/LLVMCPU/test/tile_to_vector_size.mlir index ac8fbee..bbd415b 100644 --- a/compiler/src/iree/compiler/Codegen/LLVMCPU/test/tile_to_vector_size.mlir +++ b/compiler/src/iree/compiler/Codegen/LLVMCPU/test/tile_to_vector_size.mlir
@@ -84,3 +84,23 @@ // CHECK-SAME: step %[[C30]] // CHECK-NOT: scf.for // CHECK: linalg.matmul + +// ----- + +// A fill is tiled to its vector sizes like any other op. + +#config = #iree_cpu.lowering_config<vector_common_parallel = [4, 8]> +func.func @fill_untiled(%value : f32, %init : tensor<16x16xf32>) -> tensor<16x16xf32> { + %0 = linalg.fill {lowering_config = #config} + ins(%value : f32) outs(%init : tensor<16x16xf32>) -> tensor<16x16xf32> + return %0 : tensor<16x16xf32> +} +// CHECK-LABEL: func.func @fill_untiled( +// CHECK-DAG: %[[C4:.+]] = arith.constant 4 : index +// CHECK-DAG: %[[C8:.+]] = arith.constant 8 : index +// CHECK: scf.for +// CHECK-SAME: step %[[C4]] +// CHECK: scf.for +// CHECK-SAME: step %[[C8]] +// CHECK: linalg.fill +// CHECK-SAME: outs(%{{.+}} : tensor<4x8xf32>)