[llvm] 55b38ae - [SPIRV] Emit FPFastMathMode for Call (#211879)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 4 06:49:01 PDT 2026
Author: Marcos Maronas
Date: 2026-08-04T14:48:57+01:00
New Revision: 55b38aeec8cf7de86c9c4500f59c35fc47264833
URL: https://github.com/llvm/llvm-project/commit/55b38aeec8cf7de86c9c4500f59c35fc47264833
DIFF: https://github.com/llvm/llvm-project/commit/55b38aeec8cf7de86c9c4500f59c35fc47264833.diff
LOG: [SPIRV] Emit FPFastMathMode for Call (#211879)
`SPV_KHR_float_controls2` makes `FPFastMathMode` valid for all core
instructions, so this patch enables translation of fast math flags for
`OpFunctionCall`.
Added:
llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_float_controls2/fp-fast-math-mode-function-call.ll
Modified:
llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
llvm/lib/Target/SPIRV/SPIRVInstrInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp b/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
index 01f5873b20e42..d0d96ede98e48 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
@@ -615,7 +615,7 @@ bool SPIRVCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
}
unsigned CallOp;
- if (Info.CB->isIndirectCall()) {
+ if (Info.CB && Info.CB->isIndirectCall()) {
if (!ST->canUseExtension(SPIRV::Extension::SPV_INTEL_function_pointers))
report_fatal_error("An indirect call is encountered but SPIR-V without "
"extensions does not support it",
@@ -663,6 +663,9 @@ bool SPIRVCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
MIB.addUse(Arg.Regs[0]);
}
+ if (Info.CB)
+ MIB.getInstr()->copyIRFlags(*Info.CB);
+
if (ST->canUseExtension(SPIRV::Extension::SPV_INTEL_memory_access_aliasing)) {
// Process aliasing metadata.
const CallBase *CI = Info.CB;
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstrInfo.cpp b/llvm/lib/Target/SPIRV/SPIRVInstrInfo.cpp
index fb483bb977cde..cc2d96f2e0e89 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstrInfo.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstrInfo.cpp
@@ -166,6 +166,7 @@ bool SPIRVInstrInfo::canUseFastMathFlags(const MachineInstr &MI,
case SPIRV::OpFUnordGreaterThan:
case SPIRV::OpFUnordGreaterThanEqual:
case SPIRV::OpExtInst:
+ case SPIRV::OpFunctionCall:
return KHRFloatControls2 ? true : false;
default:
return false;
diff --git a/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_float_controls2/fp-fast-math-mode-function-call.ll b/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_float_controls2/fp-fast-math-mode-function-call.ll
new file mode 100644
index 0000000000000..31707b541fa78
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_float_controls2/fp-fast-math-mode-function-call.ll
@@ -0,0 +1,41 @@
+; Verify that FPFastMathMode decorations are emitted for OpFunctionCall when
+; SPV_KHR_float_controls2 is enabled. Also verify that non-core instructions
+; (e.g. OpGroupFMulKHR from SPV_KHR_uniform_group_instructions)do NOT get a
+; spurious FPFastMathMode decoration. SPV_KHR_float_controls2 extends
+; FPFastMathMode to all *core* instructions, but not to extension-defined ones.
+
+; Without FC2: no decoration on call.
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_KHR_uniform_group_instructions %s -o - | FileCheck %s --check-prefix=NO-DECO
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_KHR_uniform_group_instructions %s -o - -filetype=obj | spirv-val %}
+
+; With FC2: decoration emitted on OpFunctionCall, not on extension instructions.
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_KHR_float_controls2,+SPV_KHR_uniform_group_instructions %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_KHR_float_controls2,+SPV_KHR_uniform_group_instructions %s -o - -filetype=obj | spirv-val %}
+
+; NO-DECO-NOT: FPFastMathMode
+
+; CHECK-DAG: OpDecorate %[[#CALL_RES:]] FPFastMathMode NotNaN|NotInf|NSZ|AllowRecip|AllowContract|AllowReassoc|AllowTransform
+; CHECK-DAG: %[[#CALL_RES]] = OpFunctionCall %[[#]] %[[#]]
+; CHECK-DAG: %[[#GFMUL_RES:]] = OpGroupFMulKHR
+
+; OpGroupFMulKHR is defined by SPV_KHR_uniform_group_instructions, not core.
+; It should NOT get FPFastMathMode because FC2 only covers core instructions.
+; CHECK-NOT: OpDecorate %[[#GFMUL_RES]] FPFastMathMode
+
+define internal spir_func float @helper(float %x) {
+ %r = fmul float %x, %x
+ ret float %r
+}
+
+declare spir_func float @_Z20__spirv_GroupFMulKHR(i32, i32, float)
+
+define spir_kernel void @test(ptr addrspace(1) %out, float %a) {
+entry:
+ %call_fast = call fast spir_func float @helper(float %a)
+ store float %call_fast, ptr addrspace(1) %out, align 4
+
+ %gfmul_fast = call fast spir_func float @_Z20__spirv_GroupFMulKHR(i32 2, i32 0, float %a)
+ store float %gfmul_fast, ptr addrspace(1) %out, align 4
+
+ ret void
+}
More information about the llvm-commits
mailing list