[llvm] [SPIR-V] Derive FPFastMathMode from nofpclass attributes on OpenCL builtins (PR #188984)

Dmitry Sidorov via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 30 03:11:09 PDT 2026


================
@@ -1279,6 +1279,29 @@ static bool generateExtInst(const SPIRV::IncomingCall *Call,
     MIB.getInstr()->setFlag(MachineInstr::MIFlag::FmNoNans);
     MIB.getInstr()->setFlag(MachineInstr::MIFlag::FmNoInfs);
   }
+
+  // Derive fast-math flags from nofpclass attributes on the called function.
+  if (ST.isKernel() &&
+      ST.canUseExtension(SPIRV::Extension::SPV_KHR_float_controls2)) {
----------------
MrSidims wrote:

```suggestion
  if (ST.isKernel() ||
      ST.canUseExtension(SPIRV::Extension::SPV_KHR_float_controls2)) {
```
per [core specification](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#FP_Fast_Math_Mode) FPFastMathMode is always allowed on several instructions with extension instructions added in allow list in SPIR-V 1.6 (including ExtInst).

per [SPV_KHR_float_controls2](https://github.khronos.org/SPIRV-Registry/extensions/KHR/SPV_KHR_float_controls2.html) it becomes legal to apply the decoration on instructions from GLSL ExtInstSet:
`Following the introduction, add "For environments that allow use of FPFastMathMode decorations on OpExtInst instructions, FPFastMathMode decorations may be applied to any instruction which uses any floating-point type for either operands or result".`


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


More information about the llvm-commits mailing list