diff options
author | Victor Lomuller <victor@codeplay.com> | 2025-04-28 17:05:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-28 18:05:06 +0200 |
commit | 0cd20537c697672bf0e7789b19bac63eb04f50f8 (patch) | |
tree | 701d6ffa7db7c6fd727f99bd590afcca1bed7b2d | |
parent | 7ee0097b486b31be8b9a1750b2cd47580efd9587 (diff) | |
download | llvm-0cd20537c697672bf0e7789b19bac63eb04f50f8.zip llvm-0cd20537c697672bf0e7789b19bac63eb04f50f8.tar.gz llvm-0cd20537c697672bf0e7789b19bac63eb04f50f8.tar.bz2 |
[SPIRV] Stop unconditionally emitting SPV_INTEL_arbitrary_precision_integers when allowed (#137167)
When the SPV_INTEL_arbitrary_precision_integers extension is allowed to
be used, the backend will unconditionnally add it to the module used
extensions.
The patch prevent SPV_INTEL_arbitrary_precision_integers from being
declared if unneeded.
-rw-r--r-- | llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp | 4 | ||||
-rw-r--r-- | llvm/test/CodeGen/SPIRV/extensions/unused-but-allowed-SPV_INTEL_arbitrary_precision_integers.ll | 19 |
2 files changed, 22 insertions, 1 deletions
diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp index 4ce316e..31b8ffe 100644 --- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp @@ -27,6 +27,7 @@ #include "llvm/IR/IntrinsicsSPIRV.h" #include "llvm/IR/Type.h" #include "llvm/Support/Casting.h" +#include "llvm/Support/MathExtras.h" #include <cassert> #include <functional> @@ -175,7 +176,8 @@ SPIRVType *SPIRVGlobalRegistry::getOpTypeInt(unsigned Width, const SPIRVSubtarget &ST = cast<SPIRVSubtarget>(MIRBuilder.getMF().getSubtarget()); return createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) { - if (ST.canUseExtension( + if ((!isPowerOf2_32(Width) || Width < 8) && + ST.canUseExtension( SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers)) { MIRBuilder.buildInstr(SPIRV::OpExtension) .addImm(SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers); diff --git a/llvm/test/CodeGen/SPIRV/extensions/unused-but-allowed-SPV_INTEL_arbitrary_precision_integers.ll b/llvm/test/CodeGen/SPIRV/extensions/unused-but-allowed-SPV_INTEL_arbitrary_precision_integers.ll new file mode 100644 index 0000000..2c12574 --- /dev/null +++ b/llvm/test/CodeGen/SPIRV/extensions/unused-but-allowed-SPV_INTEL_arbitrary_precision_integers.ll @@ -0,0 +1,19 @@ +; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown --spirv-ext=+SPV_INTEL_arbitrary_precision_integers %s -o - | FileCheck %s + +define i8 @getConstantI8() { + ret i8 2 +} +define i16 @getConstantI16() { + ret i16 2 +} +define i32 @getConstantI32() { + ret i32 2 +} + +define i64 @getConstantI64() { + ret i64 42 +} + +;; Capabilities: +; CHECK-NOT: OpExtension "SPV_INTEL_arbitrary_precision_integers" +; CHECK-NOT: OpCapability ArbitraryPrecisionIntegersINTEL |