Skip to content

Canonicalize triton::ReduceOp select(cmpf) patterns to min/max operations#11

Closed
enjustli wants to merge 1 commit intofacebookincubator:mainfrom
enjustli:fork_ms_pr_361
Closed

Canonicalize triton::ReduceOp select(cmpf) patterns to min/max operations#11
enjustli wants to merge 1 commit intofacebookincubator:mainfrom
enjustli:fork_ms_pr_361

Conversation

@enjustli
Copy link
Copy Markdown
Contributor

fork from microsoft/triton-shared#361

This PR introduces a pattern rewrite that simplifies triton::ReduceOp bodies containing arith.select operations based on floating-point comparisons. The transformation replaces select-based logic with equivalent min/max operations, improving IR canonicalization and enabling further optimization.

Supported Transformations:
select(cmpf ogt a, b), a, b → arith.maxf(a, b)
select(cmpf olt a, b), a, b → arith.minf(a, b)
select((cmpf ogt a, b) || cmpf une a, a), a, b → arith.maximumf(a, b)
select((cmpf olt a, b) || cmpf une a, a), a, b → arith.minimumf(a, b)
Applying this transformation before the ReduceOp converter runs allows the natural lowering of tt.reduce to linalg.reduce; the motivational use case was from a torch-inductor spit out Triton kernel which consisted of this complex pattern in the reduction body and did not allow the ReduceOp to get lowered to the linalg dialect.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 31, 2026
@enjustli
Copy link
Copy Markdown
Contributor Author

@nhat-nguyen

@mitekoth
Copy link
Copy Markdown
Contributor

Thanks for creating this PR here @enjustli. A colleague from Qualcomm created the microsoft PR and I can also help merge this if needed.

@enjustli
Copy link
Copy Markdown
Contributor Author

enjustli commented Apr 1, 2026

thank you!

@mitekoth
Copy link
Copy Markdown
Contributor

@enjustli Please close this PR as this is now a duplicate of #21

@enjustli enjustli closed this Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants