Skip to content

Commit 006f56e

Browse files
authored
[SPIRV-V Extension] fpbuiltin-max-error w/o extension (#2279)
Report an error if fpbuiltin-max-error attribute found without extension enabled Signed-off-by: Lu, John <[email protected]>
1 parent 3b6ff3e commit 006f56e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,15 @@ static bool recursiveType(const StructType *ST, const Type *Ty) {
305305
// Add decoration if needed
306306
void addFPBuiltinDecoration(SPIRVModule *BM, Instruction *Inst,
307307
SPIRVInstruction *I) {
308-
if (!BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_fp_max_error))
309-
return;
308+
bool AllowFPMaxError =
309+
BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_fp_max_error);
310+
310311
auto *II = dyn_cast_or_null<IntrinsicInst>(Inst);
311312
if (II && II->getCalledFunction()->getName().starts_with("llvm.fpbuiltin")) {
312313
// Add a new decoration for llvm.builtin intrinsics, if needed
313314
if (II->getAttributes().hasFnAttr("fpbuiltin-max-error")) {
315+
BM->getErrorLog().checkError(AllowFPMaxError, SPIRVEC_RequiresExtension,
316+
"SPV_INTEL_fp_max_error\n");
314317
double F = 0.0;
315318
II->getAttributes()
316319
.getFnAttr("fpbuiltin-max-error")
@@ -320,6 +323,8 @@ void addFPBuiltinDecoration(SPIRVModule *BM, Instruction *Inst,
320323
convertFloatToSPIRVWord(F));
321324
}
322325
} else if (auto *MD = Inst->getMetadata("fpmath")) {
326+
if (!AllowFPMaxError)
327+
return;
323328
auto *MDVal = mdconst::dyn_extract<ConstantFP>(MD->getOperand(0));
324329
double ValAsDouble = MDVal->getValue().convertToFloat();
325330
I->addDecorate(DecorationFPMaxErrorDecorationINTEL,

test/extensions/INTEL/SPV_INTEL_fp_max_error/IntelFPMaxError.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
; RUN: llvm-as %s -o %t.bc
2+
3+
;; Check that an error is reported if a fpbuiltin-max-error attribute is encountered without the SPV_INTEL_fp_max_error
4+
;; extension.
5+
; RUN: not llvm-spirv %t.bc --spirv-allow-unknown-intrinsics=llvm.fpbuiltin -o %t.spv 2>&1 | FileCheck %s --check-prefix=CHECK_NO_CAPABILITY_ERROR
6+
; CHECK_NO_CAPABILITY_ERROR: RequiresExtension: Feature requires the following SPIR-V extension:
7+
; CHECK_NO_CAPABILITY_ERROR-NEXT: SPV_INTEL_fp_max_error
8+
9+
;; Check that fpbuiltin-max-error is translated and reverse-translated properly
210
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_fp_max_error --spirv-allow-unknown-intrinsics=llvm.fpbuiltin -o %t.spv
311
; RUN: llvm-spirv %t.spv -to-text -o %t.spt
412
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV

0 commit comments

Comments
 (0)