Skip to content

[Codegen][CPU] Run HoistInnerTiledAccReshapes before vector lowering. - #24491

Merged
bjacob merged 1 commit into
mainfrom
users/bjacob/cpu-hoist-inner-tiled-acc-reshapes
May 15, 2026
Merged

bjacob merged 1 commit into
mainfrom
users/bjacob/cpu-hoist-inner-tiled-acc-reshapes

Conversation

@bjacob

@bjacob bjacob commented May 14, 2026

Copy link
Copy Markdown
Collaborator

Mirrors the GPU pipeline (buildLLVMGPUCodegenPassPipeline adds this pass right before UnrollToIntrinsicsPass). Before this change, on CPU the reshape ops left around iree_codegen.inner_tiled sat between the K-reduction loop's scf.for iter args and the op's accumulator operand, so the per-tile HoistableConversionOp pairs that the inner_tiled lowering wraps around its ACC distribute/reassemble couldn't satisfy
HoistConversionFromLoopPattern's strict iter-arg match. They failed to hoist, got inlined in place, and
EliminateHoistableConversions fired a hoistable_conversion was not hoisted or cancelled; inlining in place remark on every CPU matmul build using the inner_tiled path.

Running HoistInnerTiledAccReshapes before
LLVMCPUVirtualVectorLoweringPass wraps the prefix/suffix reshape ops (transpose, shape_cast, broadcast) around the inner_tiled as acc_reshape_to_intrinsic / acc_reshape_from_intrinsic hoistable conversions and runs the elimination over them. The reshapes hoist out of the K loop, the inner_tiled's accumulator is fed directly by the iter arg, and the per-tile conversion pairs emitted later in the vector lowering see direct iter-arg inputs and hoist cleanly.

Progress towards #24323.

@bjacob bjacob mentioned this pull request May 14, 2026
25 of 28 tasks
@bjacob
bjacob marked this pull request as ready for review May 14, 2026 20:32
@bjacob
bjacob requested a review from hanhanW as a code owner May 14, 2026 20:32
@bjacob

bjacob commented May 14, 2026

Copy link
Copy Markdown
Collaborator Author

@hanhanW : no test here because I didn't find an easy way to lit-test this, but the very next PR after this is e2e testing, which brings real coverage for this, seeing that this PR was necessary to make the e2e tests pass.

@bjacob
bjacob force-pushed the users/bjacob/codegen-skip-noop-swizzle-transpose branch from e7cf2f6 to 68100a9 Compare May 15, 2026 14:04
@bjacob
bjacob force-pushed the users/bjacob/cpu-hoist-inner-tiled-acc-reshapes branch from 4700ab6 to 721339b Compare May 15, 2026 14:04
Base automatically changed from users/bjacob/codegen-skip-noop-swizzle-transpose to main May 15, 2026 14:54
@bjacob
bjacob force-pushed the users/bjacob/cpu-hoist-inner-tiled-acc-reshapes branch 2 times, most recently from 1b21938 to faa3f21 Compare May 15, 2026 16:02
@bjacob
bjacob changed the base branch from main to users/bjacob/codegen-swizzle-fold-skip-gpu May 15, 2026 16:04
@bjacob
bjacob changed the base branch from users/bjacob/codegen-swizzle-fold-skip-gpu to main May 15, 2026 17:06
Mirrors the GPU pipeline (`buildLLVMGPUCodegenPassPipeline` adds this
pass right before `UnrollToIntrinsicsPass`). Before this change, on
CPU the reshape ops left around `iree_codegen.inner_tiled` sat
between the K-reduction loop's `scf.for` iter args and the op's
accumulator operand, so the per-tile `HoistableConversionOp` pairs
that the inner_tiled lowering wraps around its ACC
distribute/reassemble couldn't satisfy
`HoistConversionFromLoopPattern`'s strict iter-arg match. They
failed to hoist, got inlined in place, and
`EliminateHoistableConversions` fired a `hoistable_conversion was
not hoisted or cancelled; inlining in place` remark on every CPU
matmul build using the inner_tiled path.

Running `HoistInnerTiledAccReshapes` before
`LLVMCPUVirtualVectorLoweringPass` wraps the prefix/suffix reshape
ops (transpose, shape_cast, broadcast) around the inner_tiled as
`acc_reshape_to_intrinsic` / `acc_reshape_from_intrinsic` hoistable
conversions and runs the elimination over them. The reshapes hoist
out of the K loop, the inner_tiled's accumulator is fed directly by
the iter arg, and the per-tile conversion pairs emitted later in
the vector lowering see direct iter-arg inputs and hoist cleanly.

Progress towards #24323.

Signed-off-by: Benoit Jacob <[email protected]>
@bjacob
bjacob force-pushed the users/bjacob/cpu-hoist-inner-tiled-acc-reshapes branch from faa3f21 to 57bbcbc Compare May 15, 2026 17:06
@bjacob
bjacob merged commit 7af48c8 into main May 15, 2026
67 checks passed
@bjacob
bjacob deleted the users/bjacob/cpu-hoist-inner-tiled-acc-reshapes branch May 15, 2026 19:38
RattataKing pushed a commit to RattataKing/iree that referenced this pull request May 27, 2026
…iree-org#24491)

Mirrors the GPU pipeline (`buildLLVMGPUCodegenPassPipeline` adds this
pass right before `UnrollToIntrinsicsPass`). Before this change, on CPU
the reshape ops left around `iree_codegen.inner_tiled` sat between the
K-reduction loop's `scf.for` iter args and the op's accumulator operand,
so the per-tile `HoistableConversionOp` pairs that the inner_tiled
lowering wraps around its ACC distribute/reassemble couldn't satisfy
`HoistConversionFromLoopPattern`'s strict iter-arg match. They failed to
hoist, got inlined in place, and
`EliminateHoistableConversions` fired a `hoistable_conversion was not
hoisted or cancelled; inlining in place` remark on every CPU matmul
build using the inner_tiled path.

Running `HoistInnerTiledAccReshapes` before
`LLVMCPUVirtualVectorLoweringPass` wraps the prefix/suffix reshape ops
(transpose, shape_cast, broadcast) around the inner_tiled as
`acc_reshape_to_intrinsic` / `acc_reshape_from_intrinsic` hoistable
conversions and runs the elimination over them. The reshapes hoist out
of the K loop, the inner_tiled's accumulator is fed directly by the iter
arg, and the per-tile conversion pairs emitted later in the vector
lowering see direct iter-arg inputs and hoist cleanly.

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