Skip to content

[SPIRV] Fix disabling of default extensions - #183325

Merged
sarnex merged 1 commit into
llvm:mainfrom
sarnex:fixdisable
Feb 26, 2026
Merged

sarnex merged 1 commit into
llvm:mainfrom
sarnex:fixdisable

Conversation

@sarnex

@sarnex sarnex commented Feb 25, 2026

Copy link
Copy Markdown
Member

If you pass -ExtName to the --spirv-ext command line option. that should disable the extension. However some vendors have some extensions enabled by default when using a triple with that vendor, and disabling an extension with the option did not effect the default extensions.

This PR makes it so disabling an extension with the --spirv-ext option actually disables the extension.

The problem was we only considered the disabled extension when parsing the arguments for --spirv-ext, but the default extensions are added separately, so we need to store the disabled extensions and factor them in when computing the final extension set to use.

Signed-off-by: Nick Sarnie <nick.sarnie@intel.com>
@llvmbot

llvmbot commented Feb 25, 2026

Copy link
Copy Markdown
Member

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

Author: Nick Sarnie (sarnex)

Changes

If you pass -ExtName to the --spirv-ext command line option. that should disable the extension. However some vendors have some extensions enabled by default when using a triple with that vendor, and disabling an extension with the option did not effect the default extensions.

This PR makes it so disabling an extension with the --spirv-ext option actually disables the extension.

The problem was we only considered the disabled extension when parsing the arguments for --spirv-ext, but the default extensions are added separately, so we need to store the disabled extensions and factor them in when computing the final extension set to use.


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

3 Files Affected:

  • (modified) llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp (+5-2)
  • (modified) llvm/lib/Target/SPIRV/SPIRVCommandLine.h (+3)
  • (modified) llvm/test/CodeGen/SPIRV/extensions/SPV_EXT_relaxed_printf_string_address_space/non-constant-printf.ll (+3)
diff --git a/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp b/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp
index e336cf8dbaca1..31c7a61e1a3d8 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp
@@ -28,6 +28,8 @@
 
 using namespace llvm;
 
+std::set<SPIRV::Extension::Extension> SPIRVExtensionsParser::DisabledExtensions;
+
 static const std::map<StringRef, SPIRV::Extension::Extension>
     SPIRVExtensionMap = {
         {"SPV_EXT_shader_atomic_float_add",
@@ -231,7 +233,7 @@ bool SPIRVExtensionsParser::parse(cl::Option &O, StringRef ArgName,
       return O.error(
           "Extension cannot be allowed and disallowed at the same time: " +
           NameValuePair->first);
-
+    DisabledExtensions.insert(NameValuePair->second);
     Vals.erase(NameValuePair->second);
   }
 
@@ -270,7 +272,8 @@ SPIRVExtensionsParser::getValidExtensions(const Triple &TT) {
         SPIRV::OperandCategory::OperandCategory::ExtensionOperand,
         ExtensionEnum);
 
-    if (llvm::is_contained(AllowedEnv, CurrentEnvironment))
+    if (llvm::is_contained(AllowedEnv, CurrentEnvironment) &&
+        !llvm::is_contained(DisabledExtensions, ExtensionEnum))
       R.insert(ExtensionEnum);
   }
 
diff --git a/llvm/lib/Target/SPIRV/SPIRVCommandLine.h b/llvm/lib/Target/SPIRV/SPIRVCommandLine.h
index 02e847b322a77..03dba5915d06e 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCommandLine.h
+++ b/llvm/lib/Target/SPIRV/SPIRVCommandLine.h
@@ -48,6 +48,9 @@ struct SPIRVExtensionsParser
   /// target environment (i.e., OpenCL or Vulkan).
   static std::set<SPIRV::Extension::Extension>
   getValidExtensions(const Triple &TT);
+
+private:
+  static std::set<SPIRV::Extension::Extension> DisabledExtensions;
 };
 
 } // namespace llvm
diff --git a/llvm/test/CodeGen/SPIRV/extensions/SPV_EXT_relaxed_printf_string_address_space/non-constant-printf.ll b/llvm/test/CodeGen/SPIRV/extensions/SPV_EXT_relaxed_printf_string_address_space/non-constant-printf.ll
index cdbb1605afdd1..5a330dad47aa3 100644
--- a/llvm/test/CodeGen/SPIRV/extensions/SPV_EXT_relaxed_printf_string_address_space/non-constant-printf.ll
+++ b/llvm/test/CodeGen/SPIRV/extensions/SPV_EXT_relaxed_printf_string_address_space/non-constant-printf.ll
@@ -1,6 +1,9 @@
 ; RUN: llc -O0 -mtriple=spirv32-unknown-unknown --spirv-ext=+SPV_EXT_relaxed_printf_string_address_space %s -o - | FileCheck %s
 ; RUN: llc -O0 -mtriple=spirv32-intel-unknown %s -o - | FileCheck %s
 ; RUN: not llc -O0 -mtriple=spirv32-unknown-unknown %s -o %t.spvt 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
+; RUN: not llc -O0 -mtriple=spirv32-intel-unknown --spirv-ext=-SPV_EXT_relaxed_printf_string_address_space %s -o %t.spvt 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
+; RUN: not llc -O0 -mtriple=spirv32-intel-unknown --spirv-ext=all,-SPV_EXT_relaxed_printf_string_address_space %s -o %t.spvt 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
+; RUN: not llc -O0 -mtriple=spirv32-intel-unknown --spirv-ext=-SPV_EXT_relaxed_printf_string_address_space,all %s -o %t.spvt 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
 
 ; CHECK: OpExtension "SPV_EXT_relaxed_printf_string_address_space"
 ; CHECK: %[[#ExtInstSetId:]] = OpExtInstImport "OpenCL.std"


using namespace llvm;

std::set<SPIRV::Extension::Extension> SPIRVExtensionsParser::DisabledExtensions;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does it need to be ordered? Would unordered_set be good enough?

@sarnex sarnex Feb 26, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I had the same thought, but I just copied the type of the existing extensions map which is ordered. I can try changing them both to unordered if you're prefer (which makes more sense to me tbh) but I think the types should match at least

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't mind to change orderness later (assuming we have a github issue)

@sarnex sarnex Feb 26, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm happy to change the order basically immediately after merging this PR, if approved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sure, that works for me.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, will do it now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@sarnex
sarnex merged commit 7868963 into llvm:main Feb 26, 2026
14 checks passed
@llvm-ci

llvm-ci commented Feb 26, 2026

Copy link
Copy Markdown

LLVM Buildbot has detected a new failure on builder ppc64le-mlir-rhel-clang running on ppc64le-mlir-rhel-test while building llvm at step 6 "test-build-check-mlir-build-only-check-mlir".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/129/builds/39719

Here is the relevant piece of the build log for the reference
Step 6 (test-build-check-mlir-build-only-check-mlir) failure: 1200 seconds without output running [b'ninja', b'check-mlir'], attempting to kill
...
PASS: MLIR-Unit :: IR/./MLIRIRTests/38/133 (3883 of 3894)
PASS: MLIR-Unit :: IR/./MLIRIRTests/103/133 (3884 of 3894)
PASS: MLIR-Unit :: Interfaces/./MLIRInterfacesTests/11/22 (3885 of 3894)
PASS: MLIR-Unit :: Pass/./MLIRPassTests/11/14 (3886 of 3894)
PASS: MLIR-Unit :: IR/./MLIRIRTests/0/133 (3887 of 3894)
PASS: MLIR-Unit :: Interfaces/./MLIRInterfacesTests/12/22 (3888 of 3894)
PASS: MLIR-Unit :: Interfaces/./MLIRInterfacesTests/13/22 (3889 of 3894)
PASS: MLIR-Unit :: IR/./MLIRIRTests/37/133 (3890 of 3894)
PASS: MLIR :: mlir-tblgen/op-error.td (3891 of 3894)
PASS: MLIR :: mlir-reduce/dce-test.mlir (3892 of 3894)
command timed out: 1200 seconds without output running [b'ninja', b'check-mlir'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=2387.793219

sarnex added a commit that referenced this pull request Feb 27, 2026
…83567)

Review follow-up from #183325
No reason for these data structures to be ordered.

Minor annoyance when trying to use `DenseMap` because of the C++ code
for enums generated by TableGen, but not too bad.

Signed-off-by: Nick Sarnie <nick.sarnie@intel.com>
llvm-sync Bot pushed a commit to arm/arm-toolchain that referenced this pull request Feb 27, 2026
…ensions (#183567)

Review follow-up from llvm/llvm-project#183325
No reason for these data structures to be ordered.

Minor annoyance when trying to use `DenseMap` because of the C++ code
for enums generated by TableGen, but not too bad.

Signed-off-by: Nick Sarnie <nick.sarnie@intel.com>
sujianIBM pushed a commit to sujianIBM/llvm-project that referenced this pull request Mar 5, 2026
If you pass `-ExtName` to the `--spirv-ext` command line option. that
should disable the extension. However some vendors have some extensions
enabled by default when using a triple with that vendor, and disabling
an extension with the option did not effect the default extensions.

This PR makes it so disabling an extension with the `--spirv-ext` option
actually disables the extension.

The problem was we only considered the disabled extension when parsing
the arguments for `--spirv-ext`, but the default extensions are added
separately, so we need to store the disabled extensions and factor them
in when computing the final extension set to use.

Signed-off-by: Nick Sarnie <nick.sarnie@intel.com>
sujianIBM pushed a commit to sujianIBM/llvm-project that referenced this pull request Mar 5, 2026
…vm#183567)

Review follow-up from llvm#183325
No reason for these data structures to be ordered.

Minor annoyance when trying to use `DenseMap` because of the C++ code
for enums generated by TableGen, but not too bad.

Signed-off-by: Nick Sarnie <nick.sarnie@intel.com>
markrvmurray pushed a commit to markrvmurray/llvm-mc6809 that referenced this pull request Jun 14, 2026
…83567)

Review follow-up from llvm/llvm-project#183325
No reason for these data structures to be ordered.

Minor annoyance when trying to use `DenseMap` because of the C++ code
for enums generated by TableGen, but not too bad.

Signed-off-by: Nick Sarnie <nick.sarnie@intel.com>
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.

5 participants