Skip to content

Commit a567b25

Browse files
LU-JOHNsys-ce-bb
authored andcommitted
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]> Original commit: KhronosGroup/SPIRV-LLVM-Translator@006f56e
1 parent f3df1c7 commit a567b25

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,15 @@ static bool recursiveType(const StructType *ST, const Type *Ty) {
309309
// Add decoration if needed
310310
void addFPBuiltinDecoration(SPIRVModule *BM, Instruction *Inst,
311311
SPIRVInstruction *I) {
312-
if (!BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_fp_max_error))
313-
return;
312+
bool AllowFPMaxError =
313+
BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_fp_max_error);
314+
314315
auto *II = dyn_cast_or_null<IntrinsicInst>(Inst);
315316
if (II && II->getCalledFunction()->getName().starts_with("llvm.fpbuiltin")) {
316317
// Add a new decoration for llvm.builtin intrinsics, if needed
317318
if (II->getAttributes().hasFnAttr("fpbuiltin-max-error")) {
319+
BM->getErrorLog().checkError(AllowFPMaxError, SPIRVEC_RequiresExtension,
320+
"SPV_INTEL_fp_max_error\n");
318321
double F = 0.0;
319322
II->getAttributes()
320323
.getFnAttr("fpbuiltin-max-error")
@@ -324,6 +327,8 @@ void addFPBuiltinDecoration(SPIRVModule *BM, Instruction *Inst,
324327
convertFloatToSPIRVWord(F));
325328
}
326329
} else if (auto *MD = Inst->getMetadata("fpmath")) {
330+
if (!AllowFPMaxError)
331+
return;
327332
auto *MDVal = mdconst::dyn_extract<ConstantFP>(MD->getOperand(0));
328333
double ValAsDouble = MDVal->getValue().convertToFloat();
329334
I->addDecorate(DecorationFPMaxErrorDecorationINTEL,

llvm-spirv/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)