Repository navigation
Description
What happened?
Summary
LLVMGPU's default configuration for a contraction with multiple reduction iterators leaves the outer reduction dimensions untiled. In the standalone pass reproducer below, a single linalg.generic becomes a vector.contract containing those full-sized reduction dimensions, then expands into a large FMA chain.
For reduction extents [128, 112, 112], the generated IR contains 14,336 vector math.fma operations, 129,065 lines, and 13,280,649 bytes. Changing only the reduction tile attribute to [0, 0, 1, 1, 16] and running the same passes produces 16 FMAs, 188 lines, and 17,219 bytes.
Steps to reproduce your issue
Reproducer
Save as repro.mlir:
#lhs = affine_map<(m, n, k0, k1, k2) -> (m, k0, k1, k2)>
#rhs = affine_map<(m, n, k0, k1, k2) -> (n, k0, k1, k2)>
#out = affine_map<(m, n, k0, k1, k2) -> (m, n)>
module {
func.func @multi_reduction(
%lhs: tensor<2x8x8x32xf32>,
%rhs: tensor<3x8x8x32xbf16>,
%acc: tensor<2x3xf32>) -> tensor<2x3xf32> {
%r = linalg.generic {
indexing_maps = [#lhs, #rhs, #out],
iterator_types = ["parallel", "parallel", "reduction", "reduction", "reduction"]
} ins(%lhs, %rhs : tensor<2x8x8x32xf32>, tensor<3x8x8x32xbf16>)
outs(%acc : tensor<2x3xf32>) {
^bb0(%a: f32, %b: bf16, %c: f32):
%b32 = arith.extf %b : bf16 to f32
%product = arith.mulf %a, %b32 : f32
%sum = arith.addf %c, %product : f32
linalg.yield %sum : f32
} -> tensor<2x3xf32>
return %r : tensor<2x3xf32>
}
}This contains one contraction with loop order [m, n, k0, k1, k2]. The small case uses reduction extents [8, 8, 32]. Create the larger case by changing only those extents:
python3 - <<'PY'
from pathlib import Path
source = Path("repro.mlir").read_text()
Path("repro-large.mlir").write_text(
source.replace("8x8x32", "128x112x112"))
PYRun configuration selection, reduction tiling/vectorization, and FMA lowering separately to retain each intermediate output.
Small case:
iree-opt repro.mlir \
--iree-gpu-test-target=sm_80 \
--mlir-print-local-scope \
--pass-pipeline='builtin.module(iree-llvmgpu-select-lowering-strategy)' \
-o reduction-configured.mlir
iree-opt reduction-configured.mlir \
--pass-pipeline='builtin.module(func.func(iree-codegen-gpu-apply-tiling-level{tiling-level=reduction},canonicalize,iree-codegen-generic-vectorization))' \
-o reduction-small-vectorized.mlir
iree-opt reduction-small-vectorized.mlir \
--pass-pipeline='builtin.module(func.func(iree-llvmgpu-vector-lowering))' \
-o reduction-small-expanded.mlirLarger case:
iree-opt repro-large.mlir \
--iree-gpu-test-target=sm_80 \
--mlir-print-local-scope \
--pass-pipeline='builtin.module(iree-llvmgpu-select-lowering-strategy)' \
-o reduction-large-configured.mlir
iree-opt reduction-large-configured.mlir \
--pass-pipeline='builtin.module(func.func(iree-codegen-gpu-apply-tiling-level{tiling-level=reduction},canonicalize,iree-codegen-generic-vectorization))' \
-o reduction-large-vectorized.mlir
iree-opt reduction-large-vectorized.mlir \
--pass-pipeline='builtin.module(func.func(iree-llvmgpu-vector-lowering))' \
-o reduction-large-expanded.mlirAll six pass commands exit with code 0, with default verification enabled.
Actual behavior
Both shapes select TileAndFuse and the following reduction tiles:
reduction = [0, 0, 0, 0, 1]
In the larger case, reduction tiling creates a serial loop over k2 from zero to 112 with step one. The slices inside that loop still contain the full k0 = 128 and k1 = 112 dimensions:
%extracted_slice = tensor.extract_slice %arg0[0, 0, 0, %arg3]
[2, 128, 112, 1] [1, 1, 1, 1]
: tensor<2x128x112x112xf32> to tensor<2x128x112x1xf32>
%extracted_slice_0 = tensor.extract_slice %arg1[0, 0, 0, %arg3]
[3, 128, 112, 1] [1, 1, 1, 1]
: tensor<3x128x112x112xbf16> to tensor<3x128x112x1xbf16>The resulting contraction operand/result types are:
vector<2x128x112x1xf32>, vector<3x128x112x1xf32>
into vector<2x3xf32>
The vectorized module is only 2,181 bytes and contains one vector.contract. FMA lowering expands it into 14,336 math.fma operations and 57,346 vector.extract operations. The printed module grows to 13,280,649 bytes.
The small case exhibits the same behavior with full 8x8 outer reduction dimensions and 64 emitted FMAs.
Controlled reduction-tiling comparison
Starting from the configured larger input, change only the reduction tile attribute:
python3 - <<'PY'
from pathlib import Path
source = Path("reduction-large-configured.mlir").read_text()
old = "reduction = [0, 0, 0, 0, 1]"
assert source.count(old) == 1
Path("reduction-bounded-configured.mlir").write_text(
source.replace(old, "reduction = [0, 0, 1, 1, 16]"))
PY
iree-opt reduction-bounded-configured.mlir \
--pass-pipeline='builtin.module(func.func(iree-codegen-gpu-apply-tiling-level{tiling-level=reduction},canonicalize,iree-codegen-generic-vectorization))' \
-o reduction-bounded-vectorized.mlir
iree-opt reduction-bounded-vectorized.mlir \
--pass-pipeline='builtin.module(func.func(iree-llvmgpu-vector-lowering))' \
-o reduction-bounded-expanded.mlirBoth pass commands exit with code 0. The input tensors and all passes are unchanged. Vectorization and FMA lowering remain enabled.
The tiled IR now contains a serial loop with 100,352 iterations and an affine.delinearize_index into (128, 112, 7). Each iteration extracts slices of sizes [2, 1, 1, 16] and [3, 1, 1, 16]. The contraction types become:
vector<2x1x1x16xf32>, vector<3x1x1x16xf32>
into vector<2x3xf32>
FMA lowering emits 16 FMAs in the loop body, and the printed module is 17,219 bytes.
Recorded IR sizes
| Case | Reduction extents | Reduction tiles | Emitted FMAs | Expanded IR lines | Expanded IR bytes |
|---|---|---|---|---|---|
| Small, default configuration | [8, 8, 32] |
[0, 0, 0, 0, 1] |
64 | 617 | 58,325 |
| Larger, default configuration | [128, 112, 112] |
[0, 0, 0, 0, 1] |
14,336 | 129,065 | 13,280,649 |
| Larger, changed reduction tiles | [128, 112, 112] |
[0, 0, 1, 1, 16] |
16 | 188 | 17,219 |
FMA counts are static math.fma operations in the printed IR, each operating on vector<6xf32>. They are not execution counts. The following commands reproduce the counts and textual IR sizes:
rg -c 'math.fma' reduction-small-expanded.mlir reduction-large-expanded.mlir reduction-bounded-expanded.mlir
wc -l -c reduction-small-expanded.mlir reduction-large-expanded.mlir reduction-bounded-expanded.mlirThe larger default output and the changed-tiling output also pass standalone verification:
iree-opt reduction-large-expanded.mlir -o /dev/null
iree-opt reduction-bounded-expanded.mlir -o /dev/nullBoth commands exit with code 0.
What component(s) does this issue relate to?
Compiler
Version information
Upstream source checked
The upstream implementation was inspected at ed65de2d362643826127cc750b9ae7ac562bf877, obtained from upstream main. The local setContractConfig source matches that upstream function.
The relevant source locations are:
- TileAndFuse reduction tile construction: initializes reduction tiles to zero and sets only the last loop's tile.
- Reduction extent lookup: populates
sizeKonly for a single reduction iterator. - Dynamic-K fallback: selects
tileK = 1. ContractToChainFMA::buildFMAChain: emits a vector FMA for each flattened reduction position.
The reproduced sequence is: default reduction tiles leave two full-sized reduction dimensions in the vector contraction; FMA lowering expands those dimensions into straight-line operations. The attribute-only comparison moves those dimensions into serial iteration and keeps the contraction's reduction tile small.
Validation scope
The commands were executed with an existing local IREE iree-opt on Linux, using the upstream sm_80 test target convention. They exercise isolated compiler passes and IR verification. No compiler-source patch, complete GPU codegen pipeline, or GPU numerical execution was evaluated.
Additional context
AI assistance disclosure
OpenAI Codex assisted with reducing and executing the standalone reproducer, inspecting upstream source, collecting IR statistics, and drafting this report.
Activity
github-actions commentedon Oct 9, 2026
Hello @Cerulime 👋
Thank you for submitting an issue to IREE! It looks like it's your first one.
The volume of issues is huge, and triage times may vary. If you need quicker assistance on the issue, consider posting it on IREE Discord and providing short context there.
Feel free to identify the most frequent contributors to the corresponding part of the codebase via Git history/CODEOWNERS and (gently!) tag them below.
Action required: acknowledge IREE project policies
IREE is a Linux Foundation project. All participants are expected to follow the LF Projects Code of Conduct.
Please note that all contributions to IREE, including GitHub issues, must follow our IREE AI Tool Use Policy. This means:
For bug reports, specifics of the use-case, workflow and/or crash scenario usually suffice.
For improvement suggestions, this usually implies deeper understanding of suboptimal code, IR design choices, assumed performance tradeoffs, etc.
Before the issue can be triaged, we kindly ask you to reply to this message and confirm that you understand and accept the proposed policy. As required, please adjust your initial issue description.
If you have any questions, feel free to leave a comment here, or ask away on IREE Discord.
Thank you,
The IREE Community
Cerulime commentedon Oct 9, 2026
I understand it.
purnima-nlp commentedon Oct 9, 2026
May this be assigned to me