Skip to content

[PCF] Add tensor.collapse_shape fusion into pcf.generic/loop#23491

Merged
qedawkins merged 4 commits intoiree-org:mainfrom
qedawkins:fuse-collapse-shape
Mar 5, 2026
Merged

[PCF] Add tensor.collapse_shape fusion into pcf.generic/loop#23491
qedawkins merged 4 commits intoiree-org:mainfrom
qedawkins:fuse-collapse-shape

Conversation

@qedawkins
Copy link
Copy Markdown
Contributor

Fuse tensor.collapse_shape consumers into producer pcf.generic/pcf.loop ops. This supports all possible dynamic cases by emitting loops along outer dimensions, effectively unrolling the producer pcf.write_slice ops allowing for continued fusion. The alternative to this (essentially premature unrolling) is to put the reshape on the sref, though to continue fusing we still would have to do the same (or propagate the collapse, which should have already been attempted by this point).

Fuse tensor.collapse_shape consumers into producer pcf.generic/pcf.loop
ops. This supports all possible dynamic cases by emitting loops along
outer dimensions, effectively unrolling the producer `pcf.write_slice`
ops allowing for continued fusion. The alternative to this (essentially
premature unrolling) is to put the reshape on the sref, though to
continue fusing we still would have to do the same (or propagate the
collapse, which should have already been attempted by this point).

Currently this pattern fails on multi-use results to avoid situations
where we end up duplicating writes for a reshape. This is not a great
solution but the easiest thing to do right now until a better option
presents itself.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@qedawkins qedawkins requested a review from Max191 February 17, 2026 16:37
@qedawkins qedawkins marked this pull request as ready for review February 17, 2026 16:37
Copy link
Copy Markdown
Contributor

@Max191 Max191 left a comment

Choose a reason for hiding this comment

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

Overall this LGTM % some nits.

There are a lot of inline comments that probably aren't necessary here, though (I just pointed out a few, but there are a bunch more). Would be worth having Claude run through it and remove them.

I didn't carefully review the logic for correctness, but the test coverage is good, so I'm going to trust it. Maybe just add a fully dynamic collapse_shape test.

Please also make sure that you are using the affine.linearize/delinearize ops where possible.

Comment thread compiler/src/iree/compiler/Codegen/Dialect/PCF/Transforms/FuseConsumers.cpp Outdated
Comment thread compiler/src/iree/compiler/Codegen/Dialect/PCF/Transforms/FuseConsumers.cpp Outdated
Comment thread compiler/src/iree/compiler/Codegen/Dialect/PCF/Transforms/FuseConsumers.cpp Outdated
Comment thread compiler/src/iree/compiler/Codegen/Dialect/PCF/Transforms/FuseConsumers.cpp Outdated
@qedawkins qedawkins enabled auto-merge (squash) March 5, 2026 15:42
@qedawkins qedawkins merged commit c114a89 into iree-org:main Mar 5, 2026
56 checks passed
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.

3 participants