From f6dbd165c9bf579ccf3c122f9400be355c1288b4 Mon Sep 17 00:00:00 2001 From: Victor Lomuller Date: Thu, 24 Apr 2025 12:57:20 +0100 Subject: [PATCH] [SPIRV] Stop unconditionally emitting SPV_INTEL_arbitrary_precision_integers when allowed 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. --- llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp | 4 +++- ...-SPV_INTEL_arbitrary_precision_integers.ll | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 llvm/test/CodeGen/SPIRV/extensions/unused-but-allowed-SPV_INTEL_arbitrary_precision_integers.ll diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp index 4ce316ea32e1c..31b8ffe4099a7 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 #include @@ -175,7 +176,8 @@ SPIRVType *SPIRVGlobalRegistry::getOpTypeInt(unsigned Width, const SPIRVSubtarget &ST = cast(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 0000000000000..2c1257471d159 --- /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