Skip to content

[Codegen] Fix dominance issues blocking consumer fusions - #21551

Merged
Max191 merged 2 commits into
iree-org:mainfrom
Max191-agents:consumer-fusion-pattern-dominance-fix
Aug 1, 2025
Merged

Max191 merged 2 commits into
iree-org:mainfrom
Max191-agents:consumer-fusion-pattern-dominance-fix

Conversation

@Max191

@Max191 Max191 commented Jul 31, 2025

Copy link
Copy Markdown
Contributor

The consumer fusion utility upstream does not allow fusing consumers when the producer loop has any users that are dominated by the consumer to fuse, even if the other user comes from a different result of the loop. This seems to be a result of the way the transformation is implemented, and it would be a non-trivial refactor to support the case in upstream MLIR. Instead, this PR supports the case by moving the consumer (and any ops needed to obey dominance) to right after the loop before fusing.

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

Ok, this has been one of the things that I wanted to fix upstream (which has gotten more complicated than it needs to be). This is OK for now, but I'll fix it next week.

Signed-off-by: Max Dawkins <[email protected]>
@Max191
Max191 force-pushed the consumer-fusion-pattern-dominance-fix branch from 40a0d86 to bdcafdf Compare July 31, 2025 18:57
@Max191
Max191 merged commit 9c77258 into iree-org:main Aug 1, 2025
@Max191
Max191 deleted the consumer-fusion-pattern-dominance-fix branch August 1, 2025 13:46
hanhanW added a commit to hanhanW/iree that referenced this pull request Aug 8, 2025
hhkit pushed a commit to opencompl/iree that referenced this pull request Aug 8, 2025
)

The consumer fusion utility upstream does not allow fusing consumers
when the producer loop has any users that are dominated by the consumer
to fuse, even if the other user comes from a different result of the
loop. This seems to be a result of the way the transformation is
implemented, and it would be a non-trivial refactor to support the case
in upstream MLIR. Instead, this PR supports the case by moving the
consumer (and any ops needed to obey dominance) to right after the loop
before fusing.

---------

Signed-off-by: Max Dawkins <[email protected]>
Max191 added a commit to Max191-agents/iree that referenced this pull request Aug 8, 2025
Max191 added a commit to Max191-agents/iree that referenced this pull request Aug 8, 2025
Max191 added a commit that referenced this pull request Aug 8, 2025
…1551)" (#21637)

Reapplies
9c77258
with a bug fix for #21622.
Operations were being moved by the rewriter before the
FuseTilableConsumer pattern was guaranteed to succeed, which added the
ops to the pattern worklist every time the pattern failed. This caused
an infinite recursion of the pattern application. The fix is to move the
ops without the rewriter, so they will not be added to the worklist.
This op movement can also be removed once the upstream fusion
transformation is refactored to properly handle multi-result scf.forall
loops.

---------

Signed-off-by: Max Dawkins <[email protected]>
hhkit pushed a commit to opencompl/iree that referenced this pull request Aug 11, 2025
…ee-org#21551)" (iree-org#21637)

Reapplies
iree-org@9c77258
with a bug fix for iree-org#21622.
Operations were being moved by the rewriter before the
FuseTilableConsumer pattern was guaranteed to succeed, which added the
ops to the pattern worklist every time the pattern failed. This caused
an infinite recursion of the pattern application. The fix is to move the
ops without the rewriter, so they will not be added to the worklist.
This op movement can also be removed once the upstream fusion
transformation is refactored to properly handle multi-result scf.forall
loops.

---------

Signed-off-by: Max Dawkins <[email protected]>
AWoloszyn pushed a commit that referenced this pull request Dec 1, 2025
The consumer fusion utility upstream does not allow fusing consumers
when the producer loop has any users that are dominated by the consumer
to fuse, even if the other user comes from a different result of the
loop. This seems to be a result of the way the transformation is
implemented, and it would be a non-trivial refactor to support the case
in upstream MLIR. Instead, this PR supports the case by moving the
consumer (and any ops needed to obey dominance) to right after the loop
before fusing.

---------

Signed-off-by: Max Dawkins <[email protected]>
AWoloszyn pushed a commit that referenced this pull request Dec 1, 2025
…1551)" (#21637)

Reapplies
9c77258
with a bug fix for #21622.
Operations were being moved by the rewriter before the
FuseTilableConsumer pattern was guaranteed to succeed, which added the
ops to the pattern worklist every time the pattern failed. This caused
an infinite recursion of the pattern application. The fix is to move the
ops without the rewriter, so they will not be added to the worklist.
This op movement can also be removed once the upstream fusion
transformation is refactored to properly handle multi-result scf.forall
loops.

---------

Signed-off-by: Max Dawkins <[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.

3 participants