Skip to content

Conversation

@jmmartinez
Copy link
Contributor

AMD uses the translator to recover LLVM-IR from SPIRV.

Currently, the translator doesn't implement the SPV_KHR_float_controls2 extension (I'm working on it).
If this extension is used by the SPIRV module, we cannot translate it back to LLVM-IR.

I'm working on the extension, but in the meantime, lets just disable it when the target triple's vendor is amd.

Currently the SPIRV translator doesn't support this extension.
If this extension is used we cannot translate the SPIRV back to LLVM-IR.
@llvmbot
Copy link
Member

llvmbot commented Nov 26, 2025

@llvm/pr-subscribers-backend-spir-v

Author: Juan Manuel Martinez Caamaño (jmmartinez)

Changes

AMD uses the translator to recover LLVM-IR from SPIRV.

Currently, the translator doesn't implement the SPV_KHR_float_controls2 extension (I'm working on it).
If this extension is used by the SPIRV module, we cannot translate it back to LLVM-IR.

I'm working on the extension, but in the meantime, lets just disable it when the target triple's vendor is amd.


Full diff: https://github.com/llvm/llvm-project/pull/169659.diff

2 Files Affected:

  • (modified) llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp (+6)
  • (added) llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_float_controls2/disabled-on-amd.ll (+22)
diff --git a/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp b/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp
index ac09b937a584a..d394b3ac243a9 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp
@@ -248,5 +248,11 @@ SPIRVExtensionsParser::getValidExtensions(const Triple &TT) {
       R.insert(ExtensionEnum);
   }
 
+  if (TT.getVendor() == Triple::AMD) {
+    // AMD uses the translator to recover LLVM-IR from SPIRV. Currently, the
+    // translator doesn't implement the SPV_KHR_float_controls2 extension.
+    R.erase(SPIRV::Extension::SPV_KHR_float_controls2);
+  }
+
   return R;
 }
diff --git a/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_float_controls2/disabled-on-amd.ll b/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_float_controls2/disabled-on-amd.ll
new file mode 100644
index 0000000000000..879aab4de4808
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_float_controls2/disabled-on-amd.ll
@@ -0,0 +1,22 @@
+; RUN: llc -mtriple=spirv64-- --spirv-ext=all < %s | FileCheck %s --check-prefix=CHECK
+; No need to validate the output of the first command, we just want to ensure that we are on a path that triggers the use of SPV_KHR_float_controls2
+
+; RUN: llc -mtriple=spirv64-amd-amdhsa --spirv-ext=all < %s | FileCheck %s --check-prefix=CHECK-AMD
+; RUN: %if spirv-tools %{ llc -mtriple=spirv64-amd-amdhsa --spirv-ext=all < %s -filetype=obj | spirv-val %}
+
+; RUN: llc -mtriple=spirv64-amd-amdhsa --spirv-ext=+SPV_KHR_float_controls2 < %s | FileCheck %s --check-prefix=CHECK-AMD
+; RUN: %if spirv-tools %{ llc -mtriple=spirv64-amd-amdhsa --spirv-ext=+SPV_KHR_float_controls2 < %s -filetype=obj | spirv-val %}
+
+; Check that SPV_KHR_float_controls2 is not present when the target is AMD.
+; AMD's SPIRV implementation uses the translator to get bitcode from SPIRV,
+; which at the moment doesn't implement the SPV_KHR_float_controls2 extension.
+
+; CHECK: SPV_KHR_float_controls2
+; CHECK-AMD-NOT: SPV_KHR_float_controls2
+
+define spir_kernel void @foo(float %a, float %b) {
+entry:
+  ; Use contract to trigger a use of SPV_KHR_float_controls2
+  %r1 = fadd contract float %a, %b
+  ret void
+}

Copy link
Contributor

@maarquitos14 maarquitos14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objection from my side, but you could also manually enable the extensions that you want with -spirv-ext instead.

@jmmartinez jmmartinez merged commit e0c0075 into main Nov 27, 2025
13 checks passed
@jmmartinez jmmartinez deleted the users/jmmartinez/spirv/amd_disable_float_controls2 branch November 27, 2025 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants