Skip to content

Conversation

@quic-samanara
Copy link

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, barith.maxf(a, b)
  • select(cmpf olt a, b), a, barith.minf(a, b)
  • select((cmpf ogt a, b) || cmpf une a, a), a, barith.maximumf(a, b)
  • select((cmpf olt a, b) || cmpf une a, a), a, barith.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.

This patch adds a pattern rewrite that canonicalizes
triton::ReduceOp bodies which use arith.select based
on floating-point comparisons into equivalent
arith min/max ops.
@quic-samanara
Copy link
Author

@microsoft-github-policy-service agree company="Qualcomm"

@quic-samanara quic-samanara marked this pull request as ready for review October 31, 2025 16:07
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.

1 participant