[llvm] [NVPTX] Add atom.add.noftz support, avoid CAS loops when noftz is available (PR #223569)

Christian Sigg via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 11 22:36:00 PDT 2026


https://github.com/chsigg commented:

Thanks for the updates! Points 2–5 look good to me (single `FTZ` boolean, generic case, `IEEEhalf()`, PTX78, AddedComplexity).

A couple of things that might still need to be addressed:

1. `legacy-f32-add` / the flag rename. Is renaming `-nvptx-allow-ftz-atomics` a good idea, since an unknown cl option is a hard error? Besides the two tests on main (`atomicrmw-ignore-denormal-mode.ll`, `Transforms/AtomicExpand/NVPTX/atomicrmw-sub.ll`) downstream users might trip over it. Also, old `=true` actually behaves like `legacy-f32-add` rather than `fast`, so the mapping in the description changes numerics on sm_90+/ptx94. Would it make sense to keep `-nvptx-allow-ftz-atomics` as a bool (true -> fast) and drop legacy? If you'd prefer to keep legacy, keeping the old flag working might already be good enough.

2. There might be some traps when rebasing onto #217586 and #221425:
   - the f32 early return needs to be `return ExpansionKind;` rather than `None`, otherwise fsub ends up in ISel without a pattern
   - `IgnoreFTZMismatch` could become `FTZAtomics != AtomicAddBehavior::Strict || AI->hasMetadata(LLVMContext::MD_atomic_ignore_denormal_mode)`, used in both the f32 and f16 branches
   - the fsub CHECKs in `atomicrmw-sm90.ll` (and probably sm60/sm70) merge cleanly but will be stale, so they probably need regenerating
   - it might be good to have a test for metadata + noftz (e.g. strict + metadata + IEEE + global on sm_90/ptx94 -> `.noftz`; strict + metadata + preserve-sign + shared -> native `atom.shared.add.f32`)

A few small nits:
- I think Jonah's "remove this todo" was about `// TODO: Handle cases where input mode and output mode are mismatched` (still at L7762), and the other TODO got removed instead.
- L7735: `atom.add.f32.noftz` -> `atom.add.noftz.f32`
- L7801: "behavior. where"
- the "fast ... we always lower to an atom.add" comment isn't quite true for f16/bf16/f64 on older SMs

Thank you!

https://github.com/llvm/llvm-project/pull/223569


More information about the llvm-commits mailing list