Skip to content

Conversation

@Naghasan
Copy link

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.

…ntegers 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.
@llvmbot
Copy link
Member

llvmbot commented Apr 24, 2025

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

Author: Victor Lomuller (Naghasan)

Changes

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.


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

2 Files Affected:

  • (modified) llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp (+3-1)
  • (added) llvm/test/CodeGen/SPIRV/extensions/unused-but-allowed-SPV_INTEL_arbitrary_precision_integers.ll (+19)
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 <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 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

@VyacheslavLevytskyy VyacheslavLevytskyy merged commit 0cd2053 into llvm:main Apr 28, 2025
14 checks passed
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…ntegers when allowed (llvm#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.
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
…ntegers when allowed (llvm#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.
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.

3 participants