[llvm] Add support for SPV_KHR_float_controls (PR #83418)
Vyacheslav Levytskyy via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 29 05:19:00 PST 2024
https://github.com/VyacheslavLevytskyy updated https://github.com/llvm/llvm-project/pull/83418
>From 8ad7332522058a6c1aa2f1ec95bd4ae2fd1ca85c Mon Sep 17 00:00:00 2001
From: "Levytskyy, Vyacheslav" <vyacheslav.levytskyy at intel.com>
Date: Thu, 29 Feb 2024 04:35:22 -0800
Subject: [PATCH 1/2] add support for SPV_KHR_float_controls
---
llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp | 14 ++++++++++++++
llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp | 5 +++++
.../CodeGen/SPIRV/exec_mode_float_control_khr.ll | 2 ++
3 files changed, 21 insertions(+)
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
index ac3d6b362d350b..dd25f473e031ab 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
@@ -1143,6 +1143,8 @@ static void collectReqs(const Module &M, SPIRV::ModuleAnalysisInfo &MAI,
// Collect requirements for OpExecutionMode instructions.
auto Node = M.getNamedMetadata("spirv.ExecutionMode");
if (Node) {
+ // SPV_KHR_float_controls is not available until v1.4
+ bool RequireFloatControls = false, VerLower14 = !ST.isAtLeastSPIRVVer(14);
for (unsigned i = 0; i < Node->getNumOperands(); i++) {
MDNode *MDN = cast<MDNode>(Node->getOperand(i));
const MDOperand &MDOp = MDN->getOperand(1);
@@ -1152,9 +1154,21 @@ static void collectReqs(const Module &M, SPIRV::ModuleAnalysisInfo &MAI,
auto EM = Const->getZExtValue();
MAI.Reqs.getAndAddRequirements(
SPIRV::OperandCategory::ExecutionModeOperand, EM, ST);
+ // add SPV_KHR_float_controls if the version is too low
+ switch (EM) {
+ case SPIRV::ExecutionMode::DenormPreserve:
+ case SPIRV::ExecutionMode::DenormFlushToZero:
+ case SPIRV::ExecutionMode::SignedZeroInfNanPreserve:
+ case SPIRV::ExecutionMode::RoundingModeRTE:
+ case SPIRV::ExecutionMode::RoundingModeRTZ:
+ RequireFloatControls = VerLower14;
+ break;
+ }
}
}
}
+ if (RequireFloatControls && ST.canUseExtension(SPIRV::Extension::SPV_KHR_float_controls))
+ MAI.Reqs.addExtension(SPIRV::Extension::SPV_KHR_float_controls);
}
for (auto FI = M.begin(), E = M.end(); FI != E; ++FI) {
const Function &F = *FI;
diff --git a/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp b/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp
index 0e8952dc6a9c9f..30f44362dfd099 100644
--- a/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp
@@ -68,6 +68,11 @@ cl::list<SPIRV::Extension::Extension> Extensions(
"SPV_KHR_no_integer_wrap_decoration",
"Adds decorations to indicate that a given instruction does "
"not cause integer wrapping."),
+ clEnumValN(
+ SPIRV::Extension::SPV_KHR_float_controls, "SPV_KHR_float_controls",
+ "Provides new execution modes to control floating-point "
+ "computations by overriding an implementation’s default behavior "
+ "for rounding modes, denormals, signed zero, and infinities."),
clEnumValN(SPIRV::Extension::SPV_KHR_expect_assume,
"SPV_KHR_expect_assume",
"Provides additional information to a compiler, similar to "
diff --git a/llvm/test/CodeGen/SPIRV/exec_mode_float_control_khr.ll b/llvm/test/CodeGen/SPIRV/exec_mode_float_control_khr.ll
index 4da16528a8737b..473794a1ac978d 100644
--- a/llvm/test/CodeGen/SPIRV/exec_mode_float_control_khr.ll
+++ b/llvm/test/CodeGen/SPIRV/exec_mode_float_control_khr.ll
@@ -1,4 +1,5 @@
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefixes=SPV
+; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s --mattr=+spirv1.3 --spirv-extensions=SPV_KHR_float_controls -o - | FileCheck %s --check-prefixes=SPVEXT
define dso_local dllexport spir_kernel void @k_float_controls_0(i32 %ibuf, i32 %obuf) local_unnamed_addr {
entry:
@@ -29,6 +30,7 @@ entry:
!spirv.ExecutionMode = !{!15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !28, !29}
; SPV-NOT: OpExtension "SPV_KHR_float_controls"
+; SPVEXT: OpExtension "SPV_KHR_float_controls"
; SPV-DAG: OpEntryPoint {{.*}} %[[#KERNEL0:]] "k_float_controls_0"
; SPV-DAG: OpEntryPoint {{.*}} %[[#KERNEL1:]] "k_float_controls_1"
>From 1ad9eddac74ce37aab1e0131232ba37b6422be44 Mon Sep 17 00:00:00 2001
From: "Levytskyy, Vyacheslav" <vyacheslav.levytskyy at intel.com>
Date: Thu, 29 Feb 2024 05:18:49 -0800
Subject: [PATCH 2/2] apply clang-format
---
llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
index dd25f473e031ab..a27aeb92bbc24e 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
@@ -1156,18 +1156,19 @@ static void collectReqs(const Module &M, SPIRV::ModuleAnalysisInfo &MAI,
SPIRV::OperandCategory::ExecutionModeOperand, EM, ST);
// add SPV_KHR_float_controls if the version is too low
switch (EM) {
- case SPIRV::ExecutionMode::DenormPreserve:
- case SPIRV::ExecutionMode::DenormFlushToZero:
- case SPIRV::ExecutionMode::SignedZeroInfNanPreserve:
- case SPIRV::ExecutionMode::RoundingModeRTE:
- case SPIRV::ExecutionMode::RoundingModeRTZ:
- RequireFloatControls = VerLower14;
- break;
+ case SPIRV::ExecutionMode::DenormPreserve:
+ case SPIRV::ExecutionMode::DenormFlushToZero:
+ case SPIRV::ExecutionMode::SignedZeroInfNanPreserve:
+ case SPIRV::ExecutionMode::RoundingModeRTE:
+ case SPIRV::ExecutionMode::RoundingModeRTZ:
+ RequireFloatControls = VerLower14;
+ break;
}
}
}
}
- if (RequireFloatControls && ST.canUseExtension(SPIRV::Extension::SPV_KHR_float_controls))
+ if (RequireFloatControls &&
+ ST.canUseExtension(SPIRV::Extension::SPV_KHR_float_controls))
MAI.Reqs.addExtension(SPIRV::Extension::SPV_KHR_float_controls);
}
for (auto FI = M.begin(), E = M.end(); FI != E; ++FI) {
More information about the llvm-commits
mailing list