Skip to content

[Codegen] NFC: Lift InnerTiledOp lower & drop-unit-dim patterns to Codegen. - #24351

Merged
bjacob merged 1 commit into
mainfrom
users/bjacob/nfc-lift-inner-tiled-patterns
May 4, 2026
Merged

bjacob merged 1 commit into
mainfrom
users/bjacob/nfc-lift-inner-tiled-patterns

Conversation

@bjacob

@bjacob bjacob commented May 4, 2026

Copy link
Copy Markdown
Collaborator

Moves the two iree_codegen.inner_tiled rewrite patterns and their populate functions out of Codegen/Dialect/GPU/Transforms/ into Codegen/Dialect/Codegen/Transforms/LowerInnerTiled.cpp:

  • LowerInnerTiledPattern (replaces an iter-bound-empty inner_tiled with the per-intrinsic ops emitted by its kind's buildUnderlyingOperations)
  • DropInnerTiledUnitDimsPattern (folds unit iteration bounds and pulls the corresponding extract/broadcast pairs out of the loop)

Both patterns operate on IREE::Codegen::InnerTiledOp and dispatch through the kind's interface, so there is nothing GPU-specific about them. Lifting them lets CPU pass authors share the same lowering logic without a Codegen/Dialect/GPU/... include.

Renames the populate functions accordingly:

  • IREE::GPU::populateIREEGPULowerInnerTiledPatterns -> IREE::Codegen::populateLowerInnerTiledPatterns
  • IREE::GPU::populateIREEGPUDropUnitDimsPatterns -> IREE::Codegen::populateDropInnerTiledUnitDimsPatterns

The kShapeCastToIntrinsic / kShapeCastFromIntrinsic and kDropUnitDims / kAddUnitDims HoistableConversionOp tag constants move with the patterns. The remaining tag pair on the GPU side (kUnrollAccDistribute / kUnrollAccReassemble) stays in Codegen/Dialect/GPU/Transforms/Transforms.cpp since it's still only used by the GPU unroll path.

Updates the existing in-tree callers in LowerIREEGPUOps.cpp, IREEGPUExtensions.cpp, and UnrollToIntrinsics.cpp, and adjusts BUILD.bazel/CMakeLists.txt deps so GPU's transform libraries depend on IREECodegenTransforms.

Strict NFC; no functional or behavioral change.

Progress towards #24323

…degen.

Moves the two `iree_codegen.inner_tiled` rewrite patterns and their
populate functions out of `Codegen/Dialect/GPU/Transforms/` into
`Codegen/Dialect/Codegen/Transforms/LowerInnerTiled.cpp`:

  - `LowerInnerTiledPattern` (replaces an iter-bound-empty `inner_tiled`
    with the per-intrinsic ops emitted by its kind's
    `buildUnderlyingOperations`)
  - `DropInnerTiledUnitDimsPattern` (folds unit iteration bounds and
    pulls the corresponding extract/broadcast pairs out of the loop)

Both patterns operate on `IREE::Codegen::InnerTiledOp` and dispatch
through the kind's interface, so there is nothing GPU-specific about
them. Lifting them lets CPU pass authors share the same lowering logic
without a `Codegen/Dialect/GPU/...` include.

Renames the populate functions accordingly:

  - `IREE::GPU::populateIREEGPULowerInnerTiledPatterns`
        -> `IREE::Codegen::populateLowerInnerTiledPatterns`
  - `IREE::GPU::populateIREEGPUDropUnitDimsPatterns`
        -> `IREE::Codegen::populateDropInnerTiledUnitDimsPatterns`

The `kShapeCastToIntrinsic` / `kShapeCastFromIntrinsic` and
`kDropUnitDims` / `kAddUnitDims` HoistableConversionOp tag constants
move with the patterns. The remaining tag pair on the GPU side
(`kUnrollAccDistribute` / `kUnrollAccReassemble`) stays in
`Codegen/Dialect/GPU/Transforms/Transforms.cpp` since it's still only
used by the GPU unroll path.

Updates the existing in-tree callers in `LowerIREEGPUOps.cpp`,
`IREEGPUExtensions.cpp`, and `UnrollToIntrinsics.cpp`, and adjusts
BUILD.bazel/CMakeLists.txt deps so GPU's transform libraries depend on
`IREECodegenTransforms`.

Strict NFC; no functional or behavioral change.

Signed-off-by: Benoit Jacob <[email protected]>

Progress towards #24323
@bjacob bjacob mentioned this pull request May 4, 2026
25 of 28 tasks
@bjacob
bjacob marked this pull request as ready for review May 4, 2026 16:12
@bjacob
bjacob requested a review from hanhanW May 4, 2026 16:12
@bjacob
bjacob enabled auto-merge (squash) May 4, 2026 16:20
@bjacob
bjacob merged commit 1192630 into main May 4, 2026
64 of 65 checks passed
@bjacob
bjacob deleted the users/bjacob/nfc-lift-inner-tiled-patterns branch May 4, 2026 16:44
bjacob added a commit that referenced this pull request May 4, 2026
…ass.

`iree_codegen.inner_tiled` is a high-level vector op (a multi-dim
contraction whose shape is described by its kind), and lowering it to
per-intrinsic ops is "high-level vector -> lower-level dialect", which
is exactly what `LLVMCPUVirtualVectorLoweringPass` already does for
`vector.contract`, `vector.multi_reduction`, `vector.transfer_*`, and
the IREE VectorExt ops. So land the CPU `inner_tiled` lowering in
that pass rather than in a separate pass.

Three pattern populates from `IREE::Codegen` (introduced in PR #24351
and the previous NFC commit on this stack) join the target-independent
block of `LLVMCPUVirtualVectorLoweringPass`:

  - `IREE::Codegen::populateUnrollInnerTiledPatterns` unrolls any
    non-unit iter dim (typically a residual reduction tile) to unit.
  - `IREE::Codegen::populateDropInnerTiledUnitDimsPatterns` drops the
    (now-unit) iter domain so the lowered op has empty iter bounds,
    which is the precondition of...
  - `IREE::Codegen::populateLowerInnerTiledPatterns` replaces the
    iter-free vector-semantics `inner_tiled` with the per-intrinsic
    ops emitted by its kind's `buildUnderlyingOperations` — for
    `IREE::CPU::DataTiledMMAAttr` those are `llvm.call_intrinsic` ops.

These patterns only match `iree_codegen.inner_tiled`, so they are
orthogonal to the existing patterns in this pass; the
`DropVectorUnitDimsPass` that runs immediately before this one only
touches `vector.*` ops and similarly does not interact.

After the greedy pattern application, run
`IREE::Util::eliminateHoistableConversions` to cancel the inverse-pair
`util.hoistable_conversion` ops the inner_tiled lowering wraps around
the per-intrinsic ACC distribute/reassemble. GPU's `LowerIREEGPUOps`
pass calls this for the same reason; the introducing pattern set is
the right place to clean up after itself.

`LLVMCPUVirtualVectorLoweringPass` runs post-bufferization. That is
fine for `iree_codegen.inner_tiled`: by then the op is already in
vector semantics (lifted by `GenericVectorizationPass` via the
`InnerTiledOpVectorizationModel` `VectorizableOpInterface` external
model), and bufferization does not touch vectors.

Adds a focused
`compiler/src/iree/compiler/Codegen/LLVMCPU/test/virtual_vector_lowering_inner_tiled.mlir`
lit test that runs through `iree-llvmcpu-virtual-vector-lowering` and
asserts a single `llvm.fma.v16f32` call with no surviving
`util.hoistable_conversion` on the AVX-512 1x16x1 f32 single-tile case.

Updates a stale forward reference in `KernelDispatch.cpp` left over
from #24328 — the comment described the unit-iter-dim drop and per-
intrinsic lower patterns as firing inside a pass named
`LLVMCPULowerInnerTiledPass`, which never landed; they now fire
inside `LLVMCPUVirtualVectorLoweringPass`.

Signed-off-by: Benoit Jacob <[email protected]>

Progress towards #24323
bjacob added a commit that referenced this pull request May 4, 2026
…ass.

`iree_codegen.inner_tiled` is a high-level vector op (a multi-dim
contraction whose shape is described by its kind), and lowering it to
per-intrinsic ops is "high-level vector -> lower-level dialect", which
is exactly what `LLVMCPUVirtualVectorLoweringPass` already does for
`vector.contract`, `vector.multi_reduction`, `vector.transfer_*`, and
the IREE VectorExt ops. So land the CPU `inner_tiled` lowering in
that pass rather than in a separate pass.

Three pattern populates from `IREE::Codegen` (introduced in PR #24351
and the previous NFC commit on this stack) join the target-independent
block of `LLVMCPUVirtualVectorLoweringPass`:

  - `IREE::Codegen::populateUnrollInnerTiledPatterns` unrolls any
    non-unit iter dim (typically a residual reduction tile) to unit.
  - `IREE::Codegen::populateDropInnerTiledUnitDimsPatterns` drops the
    (now-unit) iter domain so the lowered op has empty iter bounds,
    which is the precondition of...
  - `IREE::Codegen::populateLowerInnerTiledPatterns` replaces the
    iter-free vector-semantics `inner_tiled` with the per-intrinsic
    ops emitted by its kind's `buildUnderlyingOperations` — for
    `IREE::CPU::DataTiledMMAAttr` those are `llvm.call_intrinsic` ops.

These patterns only match `iree_codegen.inner_tiled`, so they are
orthogonal to the existing patterns in this pass; the
`DropVectorUnitDimsPass` that runs immediately before this one only
touches `vector.*` ops and similarly does not interact.

After the greedy pattern application, run
`IREE::Util::eliminateHoistableConversions` to cancel the inverse-pair
`util.hoistable_conversion` ops the inner_tiled lowering wraps around
the per-intrinsic ACC distribute/reassemble. GPU's `LowerIREEGPUOps`
pass calls this for the same reason; the introducing pattern set is
the right place to clean up after itself.

`LLVMCPUVirtualVectorLoweringPass` runs post-bufferization. That is
fine for `iree_codegen.inner_tiled`: by then the op is already in
vector semantics (lifted by `GenericVectorizationPass` via the
`InnerTiledOpVectorizationModel` `VectorizableOpInterface` external
model), and bufferization does not touch vectors.

Adds a focused
`compiler/src/iree/compiler/Codegen/LLVMCPU/test/virtual_vector_lowering_inner_tiled.mlir`
lit test that runs through `iree-llvmcpu-virtual-vector-lowering` and
asserts a single `llvm.fma.v16f32` call with no surviving
`util.hoistable_conversion` on the AVX-512 1x16x1 f32 single-tile case.

Updates a stale forward reference in `KernelDispatch.cpp` left over
from #24328 — the comment described the unit-iter-dim drop and per-
intrinsic lower patterns as firing inside a pass named
`LLVMCPULowerInnerTiledPass`, which never landed; they now fire
inside `LLVMCPUVirtualVectorLoweringPass`.

Signed-off-by: Benoit Jacob <[email protected]>

Progress towards #24323
bjacob added a commit that referenced this pull request May 5, 2026
…ass. (#24358)

`iree_codegen.inner_tiled` is a high-level vector op (a multi-dim
contraction whose shape is described by its kind), and lowering it to
per-intrinsic ops is "high-level vector -> lower-level dialect", which
is exactly what `LLVMCPUVirtualVectorLoweringPass` already does for
`vector.contract`, `vector.multi_reduction`, `vector.transfer_*`, and
the IREE VectorExt ops. So land the CPU `inner_tiled` lowering in
that pass rather than in a separate pass.

Three pattern populates from `IREE::Codegen` (introduced in PR
#24351 and #24357) join the
target-independent
block of `LLVMCPUVirtualVectorLoweringPass`:

  - `IREE::Codegen::populateUnrollInnerTiledPatterns` unrolls any
    non-unit iter dim (typically a residual reduction tile) to unit.
  - `IREE::Codegen::populateDropInnerTiledUnitDimsPatterns` drops the
    (now-unit) iter domain so the lowered op has empty iter bounds,
    which is the precondition of...
  - `IREE::Codegen::populateLowerInnerTiledPatterns` replaces the
    iter-free vector-semantics `inner_tiled` with the per-intrinsic
    ops emitted by its kind's `buildUnderlyingOperations` — for
    `IREE::CPU::DataTiledMMAAttr` those are `llvm.call_intrinsic` ops.

These patterns only match `iree_codegen.inner_tiled`, so they are
orthogonal to the existing patterns in this pass; the
`DropVectorUnitDimsPass` that runs immediately before this one only
touches `vector.*` ops and similarly does not interact.

After the greedy pattern application, run
`IREE::Util::eliminateHoistableConversions` to cancel the inverse-pair
`util.hoistable_conversion` ops the inner_tiled lowering wraps around
the per-intrinsic ACC distribute/reassemble. GPU's `LowerIREEGPUOps`
pass calls this for the same reason; the introducing pattern set is
the right place to clean up after itself.

`LLVMCPUVirtualVectorLoweringPass` runs post-bufferization. That is
fine for `iree_codegen.inner_tiled`: by then the op is already in
vector semantics (lifted by `GenericVectorizationPass` via the
`InnerTiledOpVectorizationModel` `VectorizableOpInterface` external
model), and bufferization does not touch vectors.

Updates a stale forward reference in `KernelDispatch.cpp` left over
from #24328 — the comment described
the unit-iter-dim drop and per-
intrinsic lower patterns as firing inside a pass named
`LLVMCPULowerInnerTiledPass`, which never landed; they now fire
inside `LLVMCPUVirtualVectorLoweringPass`.

Progress towards #24323

---------

Signed-off-by: Benoit Jacob <[email protected]>
jerryyin pushed a commit that referenced this pull request May 7, 2026
…degen. (#24351)

Moves the two `iree_codegen.inner_tiled` rewrite patterns and their
populate functions out of `Codegen/Dialect/GPU/Transforms/` into
`Codegen/Dialect/Codegen/Transforms/LowerInnerTiled.cpp`:

- `LowerInnerTiledPattern` (replaces an iter-bound-empty `inner_tiled`
with the per-intrinsic ops emitted by its kind's
`buildUnderlyingOperations`)
- `DropInnerTiledUnitDimsPattern` (folds unit iteration bounds and pulls
the corresponding extract/broadcast pairs out of the loop)

Both patterns operate on `IREE::Codegen::InnerTiledOp` and dispatch
through the kind's interface, so there is nothing GPU-specific about
them. Lifting them lets CPU pass authors share the same lowering logic
without a `Codegen/Dialect/GPU/...` include.

Renames the populate functions accordingly:

- `IREE::GPU::populateIREEGPULowerInnerTiledPatterns` ->
`IREE::Codegen::populateLowerInnerTiledPatterns`
- `IREE::GPU::populateIREEGPUDropUnitDimsPatterns` ->
`IREE::Codegen::populateDropInnerTiledUnitDimsPatterns`

The `kShapeCastToIntrinsic` / `kShapeCastFromIntrinsic` and
`kDropUnitDims` / `kAddUnitDims` HoistableConversionOp tag constants
move with the patterns. The remaining tag pair on the GPU side
(`kUnrollAccDistribute` / `kUnrollAccReassemble`) stays in
`Codegen/Dialect/GPU/Transforms/Transforms.cpp` since it's still only
used by the GPU unroll path.

Updates the existing in-tree callers in `LowerIREEGPUOps.cpp`,
`IREEGPUExtensions.cpp`, and `UnrollToIntrinsics.cpp`, and adjusts
BUILD.bazel/CMakeLists.txt deps so GPU's transform libraries depend on
`IREECodegenTransforms`.

Strict NFC; no functional or behavioral change.

Progress towards #24323
jerryyin pushed a commit that referenced this pull request May 7, 2026
…ass. (#24358)

`iree_codegen.inner_tiled` is a high-level vector op (a multi-dim
contraction whose shape is described by its kind), and lowering it to
per-intrinsic ops is "high-level vector -> lower-level dialect", which
is exactly what `LLVMCPUVirtualVectorLoweringPass` already does for
`vector.contract`, `vector.multi_reduction`, `vector.transfer_*`, and
the IREE VectorExt ops. So land the CPU `inner_tiled` lowering in
that pass rather than in a separate pass.

Three pattern populates from `IREE::Codegen` (introduced in PR
#24351 and #24357) join the
target-independent
block of `LLVMCPUVirtualVectorLoweringPass`:

  - `IREE::Codegen::populateUnrollInnerTiledPatterns` unrolls any
    non-unit iter dim (typically a residual reduction tile) to unit.
  - `IREE::Codegen::populateDropInnerTiledUnitDimsPatterns` drops the
    (now-unit) iter domain so the lowered op has empty iter bounds,
    which is the precondition of...
  - `IREE::Codegen::populateLowerInnerTiledPatterns` replaces the
    iter-free vector-semantics `inner_tiled` with the per-intrinsic
    ops emitted by its kind's `buildUnderlyingOperations` — for
    `IREE::CPU::DataTiledMMAAttr` those are `llvm.call_intrinsic` ops.

These patterns only match `iree_codegen.inner_tiled`, so they are
orthogonal to the existing patterns in this pass; the
`DropVectorUnitDimsPass` that runs immediately before this one only
touches `vector.*` ops and similarly does not interact.

After the greedy pattern application, run
`IREE::Util::eliminateHoistableConversions` to cancel the inverse-pair
`util.hoistable_conversion` ops the inner_tiled lowering wraps around
the per-intrinsic ACC distribute/reassemble. GPU's `LowerIREEGPUOps`
pass calls this for the same reason; the introducing pattern set is
the right place to clean up after itself.

`LLVMCPUVirtualVectorLoweringPass` runs post-bufferization. That is
fine for `iree_codegen.inner_tiled`: by then the op is already in
vector semantics (lifted by `GenericVectorizationPass` via the
`InnerTiledOpVectorizationModel` `VectorizableOpInterface` external
model), and bufferization does not touch vectors.

Updates a stale forward reference in `KernelDispatch.cpp` left over
from #24328 — the comment described
the unit-iter-dim drop and per-
intrinsic lower patterns as firing inside a pass named
`LLVMCPULowerInnerTiledPass`, which never landed; they now fire
inside `LLVMCPUVirtualVectorLoweringPass`.

Progress towards #24323

---------

Signed-off-by: Benoit Jacob <[email protected]>
RattataKing pushed a commit to RattataKing/iree that referenced this pull request May 27, 2026
…degen. (iree-org#24351)

Moves the two `iree_codegen.inner_tiled` rewrite patterns and their
populate functions out of `Codegen/Dialect/GPU/Transforms/` into
`Codegen/Dialect/Codegen/Transforms/LowerInnerTiled.cpp`:

- `LowerInnerTiledPattern` (replaces an iter-bound-empty `inner_tiled`
with the per-intrinsic ops emitted by its kind's
`buildUnderlyingOperations`)
- `DropInnerTiledUnitDimsPattern` (folds unit iteration bounds and pulls
the corresponding extract/broadcast pairs out of the loop)

Both patterns operate on `IREE::Codegen::InnerTiledOp` and dispatch
through the kind's interface, so there is nothing GPU-specific about
them. Lifting them lets CPU pass authors share the same lowering logic
without a `Codegen/Dialect/GPU/...` include.

Renames the populate functions accordingly:

- `IREE::GPU::populateIREEGPULowerInnerTiledPatterns` ->
`IREE::Codegen::populateLowerInnerTiledPatterns`
- `IREE::GPU::populateIREEGPUDropUnitDimsPatterns` ->
`IREE::Codegen::populateDropInnerTiledUnitDimsPatterns`

The `kShapeCastToIntrinsic` / `kShapeCastFromIntrinsic` and
`kDropUnitDims` / `kAddUnitDims` HoistableConversionOp tag constants
move with the patterns. The remaining tag pair on the GPU side
(`kUnrollAccDistribute` / `kUnrollAccReassemble`) stays in
`Codegen/Dialect/GPU/Transforms/Transforms.cpp` since it's still only
used by the GPU unroll path.

Updates the existing in-tree callers in `LowerIREEGPUOps.cpp`,
`IREEGPUExtensions.cpp`, and `UnrollToIntrinsics.cpp`, and adjusts
BUILD.bazel/CMakeLists.txt deps so GPU's transform libraries depend on
`IREECodegenTransforms`.

Strict NFC; no functional or behavioral change.

Progress towards iree-org#24323
RattataKing pushed a commit to RattataKing/iree that referenced this pull request May 27, 2026
…ass. (iree-org#24358)

`iree_codegen.inner_tiled` is a high-level vector op (a multi-dim
contraction whose shape is described by its kind), and lowering it to
per-intrinsic ops is "high-level vector -> lower-level dialect", which
is exactly what `LLVMCPUVirtualVectorLoweringPass` already does for
`vector.contract`, `vector.multi_reduction`, `vector.transfer_*`, and
the IREE VectorExt ops. So land the CPU `inner_tiled` lowering in
that pass rather than in a separate pass.

Three pattern populates from `IREE::Codegen` (introduced in PR
iree-org#24351 and iree-org#24357) join the
target-independent
block of `LLVMCPUVirtualVectorLoweringPass`:

  - `IREE::Codegen::populateUnrollInnerTiledPatterns` unrolls any
    non-unit iter dim (typically a residual reduction tile) to unit.
  - `IREE::Codegen::populateDropInnerTiledUnitDimsPatterns` drops the
    (now-unit) iter domain so the lowered op has empty iter bounds,
    which is the precondition of...
  - `IREE::Codegen::populateLowerInnerTiledPatterns` replaces the
    iter-free vector-semantics `inner_tiled` with the per-intrinsic
    ops emitted by its kind's `buildUnderlyingOperations` — for
    `IREE::CPU::DataTiledMMAAttr` those are `llvm.call_intrinsic` ops.

These patterns only match `iree_codegen.inner_tiled`, so they are
orthogonal to the existing patterns in this pass; the
`DropVectorUnitDimsPass` that runs immediately before this one only
touches `vector.*` ops and similarly does not interact.

After the greedy pattern application, run
`IREE::Util::eliminateHoistableConversions` to cancel the inverse-pair
`util.hoistable_conversion` ops the inner_tiled lowering wraps around
the per-intrinsic ACC distribute/reassemble. GPU's `LowerIREEGPUOps`
pass calls this for the same reason; the introducing pattern set is
the right place to clean up after itself.

`LLVMCPUVirtualVectorLoweringPass` runs post-bufferization. That is
fine for `iree_codegen.inner_tiled`: by then the op is already in
vector semantics (lifted by `GenericVectorizationPass` via the
`InnerTiledOpVectorizationModel` `VectorizableOpInterface` external
model), and bufferization does not touch vectors.

Updates a stale forward reference in `KernelDispatch.cpp` left over
from iree-org#24328 — the comment described
the unit-iter-dim drop and per-
intrinsic lower patterns as firing inside a pass named
`LLVMCPULowerInnerTiledPass`, which never landed; they now fire
inside `LLVMCPUVirtualVectorLoweringPass`.

Progress towards iree-org#24323

---------

Signed-off-by: Benoit Jacob <[email protected]>
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.

2 participants