Repository navigation
Lower one-argument atan, copysign, muladd and float === - #327
Merged
Merged
Conversation
AntonOresten
force-pushed
the
ao/scalar-math-lowerings
branch
from
October 15, 2026 08:40
7a0f1c9 to
5d712cc
Compare
Several common scalar functions failed to compile when broadcast over a tile: - `muladd` (any float type) had no lowering for `muladd_float`. It now lowers to Tile IR's `fma`: `muladd` allows either a fused or an unfused computation, and Tile IR has a native fma. - `copysign` had no lowering for `copysign_float`. Tile IR has no copysign, so it combines the magnitude bits of one operand with the sign bit of the other. - `atan(x)` reached `copysign` through Base's implementation. It now maps to Tile IR's `atan2(x, 1)`, as the two-argument form already does. - `===` on floats was emitted as a `cmpi` on float tiles, which tileiras rejects. This broke `isinf`, which Base defines as `abs(x) === oftype(x, Inf)`. The operands are now bitcast to integers of the same width first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019SPsbjijQAL2CBmDmAYip5
AntonOresten
force-pushed
the
ao/scalar-math-lowerings
branch
from
October 15, 2026 08:41
5d712cc to
633646b
Compare
maleadt
reviewed
Oct 15, 2026
maleadt
approved these changes
Oct 15, 2026
maleadt
left a comment
Member
There was a problem hiding this comment.
Small doc nit. LGTM otherwise.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019SPsbjijQAL2CBmDmAYip5
Instead of letting `Intrinsics.cmpi` take float operands and bitcasting them in its emitter, the `===` lowering reinterprets them as unsigned integers of the same width (`Base.uinttype`): a correctly typed `Intrinsics.bitcast` for values, and the reinterpreted bit pattern for literals. `cmpi` stays integer-only, like Tile IR's `cmpi`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019SPsbjijQAL2CBmDmAYip5
Replace the imperative `===` rewrite with a one-line rule to a new `Intrinsics.egal`. Its emitter bitcasts float operands to unsigned integers of the same width (`Base.uinttype`) and emits `cmpi` through the helper it shares with `Intrinsics.cmpi`, which stays integer-only. The generated PTX is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019SPsbjijQAL2CBmDmAYip5
Collaborator
Author
|
Switched to a new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Several common scalar functions fail to compile on
mainwhen broadcast over a tile:muladd(any float type)muladd_float … has no Tile IR equivalentcopysigncopysign_float … has no Tile IR equivalentatan(x)copysignisinf'cuda_tile.cmpi' op operand #0 must be tile of i1 or i8 or i16 or i32 or i64 values, but got '!cuda_tile.tile<256xf32>'Changes:
muladd_floatlowers to Tile IR'sfma.muladdallows either a fused or an unfused computation, and Tile IR has a native fma.copysigncombines the magnitude bits of one operand with the sign bit of the other, as Tile IR has no copysign.atan(x)maps toatan2(x, 1), as the two-argument form already does.===was lowered toIntrinsics.cmpifor any operand type, so on floats it emitted acmpion float tiles. Base definesisinf(x::IEEEFloat)asabs(x) === oftype(x, Inf), soisinfhit this.===now lowers to a newIntrinsics.egal, which bitcasts float operands to unsigned integers of the same width (Base.uinttype) and then emitscmpi. This keeps==='s bitwise meaning (-0.0 !== 0.0,NaN === NaN), andIntrinsics.cmpistays integer-only, like Tile IR'scmpi. Integer operands emit the samecmpias before.Tests: device tests compare each function against the CPU, including
isinfon±Inf,NaNandfloatmax, andmuladdon Float64 values. A codegen test checks that float===emitsbitcastfollowed bycmpi.Assisted by: Opus 5.5