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

Akshay Deodhar via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 18 18:07:13 PDT 2026


================
@@ -110,16 +110,29 @@ static cl::opt<bool> UsePrecSqrtF32(
     cl::desc("NVPTX Specific: 0 use sqrt.approx, 1 use sqrt.rn."),
     cl::init(true));
 
-// PTX atom.add.f32 has fixed FTZ behavior that may not match the function's
+// PTX atom.add.f32 might not support FTZ behavior that matches the function's
 // (see shouldExpandAtomicRMWInIR), so we'd normally fall back to a CAS loop
-// when they disagree. This option (enabled by default) allows using atom.add
-// anyway, trading correct denormal handling for the speed of the native
-// instruction.
-static cl::opt<bool> AllowFTZAtomics(
-    "nvptx-allow-ftz-atomics", cl::Hidden,
-    cl::desc("NVPTX Specific: Lower atomicrmw fadd to atom.add even when its "
-             "FTZ behavior does not match the function's denormal mode."),
-    cl::init(true));
+// when they disagree. This option controls whether to use atom.add anyway,
+// trading correct denormal handling for the speed of the native instruction.
+enum class AtomicAddBehavior { Strict, LegacyF32Add, Fast };
+static cl::opt<AtomicAddBehavior> FTZAtomics(
+    "nvptx-ftz-atomics", cl::Hidden,
+    cl::desc("NVPTX Specific: How to lower atomicrmw fadd"),
+    cl::init(AtomicAddBehavior::Fast),
+    cl::values(
+        clEnumValN(AtomicAddBehavior::Strict, "strict",
+                   "Conform to the function's denormal mode, using a CAS loop "
+                   "where no atom.add matches it. PTX has no flushing add for "
+                   "f64 or bf16, so those still use the native instruction."),
+        clEnumValN(AtomicAddBehavior::LegacyF32Add, "legacy-f32-add",
----------------
akshayrdeodhar wrote:

The legacy flag is purely for giving users a way to continue to get the same numerical output that they were getting before the native .noftz instruction became available.

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


More information about the llvm-commits mailing list