nvptx: Incorrect use of LLVM intrinsics for f16x2_min/max(_nan)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 694
- Forks
- 336
- Avg merge
- 5d 14h
- Merged PRs (30d)
- 9
Description
The nvptx intrinsics f16x2_min/f16x2_max/f16x2_min_nan/f16x2_max_nan are currently being mapped to the LLVM intrinsics minnum/minimum/maxnum/maximum, respectively (in some cases this is indirected via simd_fmin/simd_fmax, which are documented to correspond to minnum nsz/maxnum nsz, but we currently don't actually emit the nsz attribute). See here for an overview of the LLVM float min/max operations.
This is incorrect:
- According to the docs, the behavior for signed zeros is defined by
(a < b) ? a : b, i.e., when both operands compare equal, the 2nd operand is returned. That's not what any of the LLVM intrinsics does: they either treat-0.0as smaller than+0.0(that's the default), or return either value non-deterministically (when thenszattribute is present). [This means it is actually a bug that LLVM uses themin.f16x2nvptx operation for loweringminnum...] - According to the docs, assuming that
isNaNchecks for both QNaN and SNaN, if exactly one input is any NaN, the other input is returned forf16x2_min/f16x2_max. In contrast,minnum/maxnumsay that when an input is SNaN, the return value is a NaN or the other input. The LLVM variant with the correct NaN semantics isminimumnum/maximumnum.
Cc @kjetilkjeka @folkertdev
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the nvptx mappings for f16x2_min, f16x2_max, f16x2_min_nan, and f16x2_max_nan, including any simd_fmin or simd_fmax indirection. Read the LLVM floating-point min/max documentation and NVIDIA's half-precision min/max documentation first; done means the mappings preserve the documented signed-zero and NaN behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100