Skip to content

Simple scalar float operations unnecessarily require libdevice #390

Closed

Description

@niklebedenko

Simple scalar float operations unnecessarily require libdevice

Problem

Rust abs, copysign, max, and min operations are lowered to libdevice
calls even though LLVM and the NVPTX backend can lower them directly to PTX.

Why this matters

A kernel using only these scalar operations is routed through the heavier
libNVVM and nvJitLink pipeline and acquires a CUDA Toolkit runtime dependency
that its generated code does not otherwise need.

Expected behavior

These operations should remain on the ordinary LLVM-to-PTX path. abs and
copysign can use their LLVM intrinsics; max and min need compare/select
lowering that matches Rust's signaling-NaN semantics. Transcendental and other
libdevice-owned functions should continue to use their existing __nv_*
lowering.

Acceptance criteria

  • abs and copysign lower to width-correct LLVM intrinsics for both widths.
  • Rust max and min ignore quiet and signaling NaNs in either operand
    position, without using LLVM 21's incompatible legacy maxnum/minnum.
  • abs produces exact finite/zero bits and clears a NaN sign without
    constraining the NaN payload.
  • copysign changes only the sign bit and preserves the magnitude operand's
    exact NaN payload.
  • Unrelated math operations continue to use libdevice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions