Skip to content

Commit 0cd2053

Browse files
authored
[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.
1 parent 7ee0097 commit 0cd2053

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "llvm/IR/IntrinsicsSPIRV.h"
2828
#include "llvm/IR/Type.h"
2929
#include "llvm/Support/Casting.h"
30+
#include "llvm/Support/MathExtras.h"
3031
#include <cassert>
3132
#include <functional>
3233

@@ -175,7 +176,8 @@ SPIRVType *SPIRVGlobalRegistry::getOpTypeInt(unsigned Width,
175176
const SPIRVSubtarget &ST =
176177
cast<SPIRVSubtarget>(MIRBuilder.getMF().getSubtarget());
177178
return createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
178-
if (ST.canUseExtension(
179+
if ((!isPowerOf2_32(Width) || Width < 8) &&
180+
ST.canUseExtension(
179181
SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers)) {
180182
MIRBuilder.buildInstr(SPIRV::OpExtension)
181183
.addImm(SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown --spirv-ext=+SPV_INTEL_arbitrary_precision_integers %s -o - | FileCheck %s
2+
3+
define i8 @getConstantI8() {
4+
ret i8 2
5+
}
6+
define i16 @getConstantI16() {
7+
ret i16 2
8+
}
9+
define i32 @getConstantI32() {
10+
ret i32 2
11+
}
12+
13+
define i64 @getConstantI64() {
14+
ret i64 42
15+
}
16+
17+
;; Capabilities:
18+
; CHECK-NOT: OpExtension "SPV_INTEL_arbitrary_precision_integers"
19+
; CHECK-NOT: OpCapability ArbitraryPrecisionIntegersINTEL

0 commit comments

Comments
 (0)