Skip to content

Commit 15dd186

Browse files
vmaksimovladimirlaz
authored andcommitted
Do not translate arbitrary precision operations without corresponding extensions (#714)
This patch addresses [comment][1] If the appropriate extension for arbitrary precision instruction is not enabled, invalid IR will be produced. Report an error in this case. [1]: KhronosGroup/SPIRV-LLVM-Translator#653 (comment)
1 parent 52c753b commit 15dd186

File tree

3 files changed

+26
-76
lines changed

3 files changed

+26
-76
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,17 +2964,26 @@ SPIRVInstruction *LLVMToSPIRV::transBuiltinToInst(StringRef DemangledName,
29642964
!BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_blocking_pipes))
29652965
return nullptr;
29662966

2967-
if (OpFixedSqrtINTEL <= OC && OC <= OpFixedExpINTEL &&
2968-
!BM->isAllowedToUseExtension(
2969-
ExtensionID::SPV_INTEL_arbitrary_precision_fixed_point))
2970-
return nullptr;
2971-
2972-
if (((OpArbitraryFloatSinCosPiINTEL <= OC &&
2973-
OC <= OpArbitraryFloatCastToIntINTEL) ||
2974-
(OpArbitraryFloatAddINTEL <= OC && OC <= OpArbitraryFloatPowNINTEL)) &&
2975-
!BM->isAllowedToUseExtension(
2976-
ExtensionID::SPV_INTEL_arbitrary_precision_floating_point))
2977-
return nullptr;
2967+
if (OpFixedSqrtINTEL <= OC && OC <= OpFixedExpINTEL)
2968+
BM->getErrorLog().checkError(
2969+
BM->isAllowedToUseExtension(
2970+
ExtensionID::SPV_INTEL_arbitrary_precision_fixed_point),
2971+
SPIRVEC_InvalidInstruction,
2972+
CI->getCalledOperand()->getName().str() +
2973+
"\nFixed point instructions can't be translated correctly without "
2974+
"enabled SPV_INTEL_arbitrary_precision_fixed_point extension!\n");
2975+
2976+
if ((OpArbitraryFloatSinCosPiINTEL <= OC &&
2977+
OC <= OpArbitraryFloatCastToIntINTEL) ||
2978+
(OpArbitraryFloatAddINTEL <= OC && OC <= OpArbitraryFloatPowNINTEL))
2979+
BM->getErrorLog().checkError(
2980+
BM->isAllowedToUseExtension(
2981+
ExtensionID::SPV_INTEL_arbitrary_precision_floating_point),
2982+
SPIRVEC_InvalidInstruction,
2983+
CI->getCalledOperand()->getName().str() +
2984+
"\nFloating point instructions can't be translated correctly "
2985+
"without enabled SPV_INTEL_arbitrary_precision_floating_point "
2986+
"extension!\n");
29782987

29792988
auto Inst = transBuiltinToInstWithoutDecoration(OC, CI, BB);
29802989
addDecorations(Inst, Dec);

llvm-spirv/test/transcoding/capability-arbitrary-precision-fixed-point-numbers.ll

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@
9595
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_arbitrary_precision_integers,+SPV_INTEL_arbitrary_precision_fixed_point -o %t.spv
9696
; RUN: llvm-spirv %t.spv -to-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV
9797

98-
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_arbitrary_precision_integers -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV-NEGATIVE
98+
; RUN: not llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_arbitrary_precision_integers -spirv-text -o - 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
99+
; CHECK-ERROR: InvalidInstruction: Can't translate llvm instruction:
100+
; CHECK-ERROR: Fixed point instructions can't be translated correctly without enabled SPV_INTEL_arbitrary_precision_fixed_point extension!
99101

100102
; RUN: llvm-spirv -r %t.spv -o %t.bc
101103
; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-LLVM
@@ -106,9 +108,6 @@
106108
; CHECK-SPIRV: 12 Extension "SPV_INTEL_arbitrary_precision_fixed_point"
107109
; CHECK-SPIRV: 11 Extension "SPV_INTEL_arbitrary_precision_integers"
108110

109-
; CHECK-SPIRV-NEGATIVE-NOT: 2 Capability ArbitraryPrecisionFixedPointINTEL
110-
; CHECK-SPIRV-NEGATIVE-NOT: 12 Extension "SPV_INTEL_arbitrary_precision_fixed_point"
111-
112111
; CHECK-SPIRV: 4 TypeInt [[Ty_8:[0-9]+]] 8 0
113112
; CHECK-SPIRV: 4 TypeInt [[Ty_13:[0-9]+]] 13 0
114113
; CHECK-SPIRV: 4 TypeInt [[Ty_5:[0-9]+]] 5 0
@@ -128,53 +127,40 @@
128127

129128
; CHECK-SPIRV: 6 Load [[Ty_13]] [[Sqrt_InId:[0-9]+]]
130129
; CHECK-SPIRV-NEXT: 9 FixedSqrtINTEL [[Ty_5]] [[#]] [[Sqrt_InId]] 0 2 2 0 0
131-
; CHECK-SPIRV-NEGATIVE-NOT: 9 FixedSqrtINTEL
132130
; CHECK-SPIRV: 6 Load [[Ty_5]] [[Sqrt_InId_B:[0-9]+]]
133131
; CHECK-SPIRV-NEXT: 9 FixedSqrtINTEL [[Ty_13]] [[#]] [[Sqrt_InId_B]] 0 2 2 0 0
134-
; CHECK-SPIRV-NEGATIVE-NOT: 9 FixedSqrtINTEL
135132
; CHECK-SPIRV: 6 Load [[Ty_5]] [[Sqrt_InId_C:[0-9]+]]
136133
; CHECK-SPIRV-NEXT: 9 FixedSqrtINTEL [[Ty_13]] [[#]] [[Sqrt_InId_C]] 0 2 2 0 0
137-
; CHECK-SPIRV-NEGATIVE-NOT: 9 FixedSqrtINTEL
138134

139135
; CHECK-SPIRV: 6 Load [[Ty_3]] [[Recip_InId:[0-9]+]]
140136
; CHECK-SPIRV-NEXT: 9 FixedRecipINTEL [[Ty_8]] [[#]] [[Recip_InId]] 1 4 4 0 0
141-
; CHECK-SPIRV-NEGATIVE-NOT: 9 FixedRecipINTEL
142137

143138
; CHECK-SPIRV: 6 Load [[Ty_11]] [[Rsqrt_InId:[0-9]+]]
144139
; CHECK-SPIRV-NEXT: 9 FixedRsqrtINTEL [[Ty_10]] [[#]] [[Rsqrt_InId]] 0 8 6 0 0
145-
; CHECK-SPIRV-NEGATIVE-NOT: 9 FixedRsqrtINTEL
146140

147141
; CHECK-SPIRV: 6 Load [[Ty_17]] [[Sin_InId:[0-9]+]]
148142
; CHECK-SPIRV-NEXT: 9 FixedSinINTEL [[Ty_11]] [[#]] [[Sin_InId]] 1 7 5 0 0
149-
; CHECK-SPIRV-NEGATIVE-NOT: 9 FixedSinINTEL
150143

151144
; CHECK-SPIRV: 6 Load [[Ty_35]] [[Cos_InId:[0-9]+]]
152145
; CHECK-SPIRV-NEXT: 9 FixedCosINTEL [[Ty_28]] [[#]] [[Cos_InId]] 0 9 3 0 0
153-
; CHECK-SPIRV-NEGATIVE-NOT: 9 FixedCosINTEL
154146

155147
; CHECK-SPIRV: 6 Load [[Ty_31]] [[SinCos_InId:[0-9]+]]
156148
; CHECK-SPIRV-NEXT: 9 FixedSinCosINTEL [[Ty_40]] [[#]] [[SinCos_InId]] 1 10 12 0 0
157-
; CHECK-SPIRV-NEGATIVE-NOT: 9 FixedSinCosINTEL
158149

159150
; CHECK-SPIRV: 6 Load [[Ty_60]] [[SinPi_InId:[0-9]+]]
160151
; CHECK-SPIRV-NEXT: 9 FixedSinPiINTEL [[Ty_5]] [[#]] [[SinPi_InId]] 0 2 2 0 0
161-
; CHECK-SPIRV-NEGATIVE-NOT: 9 FixedSinPiINTEL
162152

163153
; CHECK-SPIRV: 6 Load [[Ty_28]] [[CosPi_InId:[0-9]+]]
164154
; CHECK-SPIRV-NEXT: 9 FixedCosPiINTEL [[Ty_16]] [[#]] [[CosPi_InId]] 0 8 5 0 0
165-
; CHECK-SPIRV-NEGATIVE-NOT: 9 FixedCosPiINTEL
166155

167156
; CHECK-SPIRV: 6 Load [[Ty_13]] [[SinCosPi_InId:[0-9]+]]
168157
; CHECK-SPIRV-NEXT: 9 FixedSinCosPiINTEL [[Ty_10]] [[#]] [[SinCosPi_InId]] 0 2 2 0 0
169-
; CHECK-SPIRV-NEGATIVE-NOT: 9 FixedSinCosPiINTEL
170158

171159
; CHECK-SPIRV: 6 Load [[Ty_64]] [[Log_InId:[0-9]+]]
172160
; CHECK-SPIRV-NEXT: 9 FixedLogINTEL [[Ty_44]] [[#]] [[Log_InId]] 1 24 22 0 0
173-
; CHECK-SPIRV-NEGATIVE-NOT: 9 FixedLogINTEL
174161

175162
; CHECK-SPIRV: 6 Load [[Ty_44]] [[Exp_InId:[0-9]+]]
176163
; CHECK-SPIRV-NEXT: 9 FixedExpINTEL [[Ty_34]] [[#]] [[Exp_InId]] 0 20 20 0 0
177-
; CHECK-SPIRV-NEGATIVE-NOT: 9 FixedExpINTEL
178164

179165
; CHECK-LLVM: call i5 @intel_arbitrary_fixed_sqrt.i5.i13(i13 %[[#]], i1 false, i32 2, i32 2, i32 0, i32 0)
180166
; CHECK-LLVM: call i13 @intel_arbitrary_fixed_sqrt.i13.i5(i5 %[[#]], i1 false, i32 2, i32 2, i32 0, i32 0)

0 commit comments

Comments
 (0)