diff --git a/llvm-spirv/lib/SPIRV/SPIRVWriter.cpp b/llvm-spirv/lib/SPIRV/SPIRVWriter.cpp index 48310473ea8f4..ef3f713e1939a 100644 --- a/llvm-spirv/lib/SPIRV/SPIRVWriter.cpp +++ b/llvm-spirv/lib/SPIRV/SPIRVWriter.cpp @@ -1418,9 +1418,12 @@ LLVMToSPIRVBase::getLoopControl(const BranchInst *Branch, // PartialCount must not be used with the DontUnroll bit else if (S == "llvm.loop.unroll.count" && !(LoopControl & LoopControlDontUnrollMask)) { - size_t I = getMDOperandAsInt(Node, 1); - ParametersToSort.emplace_back(spv::LoopControlPartialCountMask, I); - LoopControl |= spv::LoopControlPartialCountMask; + if (BM->isAllowedToUseVersion(VersionNumber::SPIRV_1_4)) { + BM->setMinSPIRVVersion(VersionNumber::SPIRV_1_4); + size_t I = getMDOperandAsInt(Node, 1); + ParametersToSort.emplace_back(spv::LoopControlPartialCountMask, I); + LoopControl |= spv::LoopControlPartialCountMask; + } } else if (S == "llvm.loop.ivdep.enable") LoopControl |= spv::LoopControlDependencyInfiniteMask; else if (S == "llvm.loop.ivdep.safelen") { @@ -2481,10 +2484,10 @@ bool LLVMToSPIRVBase::transDecoration(Value *V, SPIRVValue *BV) { if (auto BVO = dyn_cast_or_null(V)) { if (BVO->hasNoSignedWrap()) { - BV->setNoSignedWrap(true); + BV->setNoIntegerDecorationWrap(true); } if (BVO->hasNoUnsignedWrap()) { - BV->setNoUnsignedWrap(true); + BV->setNoIntegerDecorationWrap(true); } } @@ -4610,43 +4613,34 @@ bool LLVMToSPIRVBase::transExecutionMode() { } } break; case spv::ExecutionModeNoGlobalOffsetINTEL: { - if (BM->isAllowedToUseExtension( - ExtensionID::SPV_INTEL_kernel_attributes)) { - BF->addExecutionMode(BM->add( - new SPIRVExecutionMode(BF, static_cast(EMode)))); - BM->addExtension(ExtensionID::SPV_INTEL_kernel_attributes); - BM->addCapability(CapabilityKernelAttributesINTEL); - } + if (!BM->isAllowedToUseExtension( + ExtensionID::SPV_INTEL_kernel_attributes)) + break; + BF->addExecutionMode(BM->add( + new SPIRVExecutionMode(BF, static_cast(EMode)))); + BM->addExtension(ExtensionID::SPV_INTEL_kernel_attributes); + BM->addCapability(CapabilityKernelAttributesINTEL); } break; case spv::ExecutionModeVecTypeHint: case spv::ExecutionModeSubgroupSize: - case spv::ExecutionModeSubgroupsPerWorkgroup: { - unsigned X; - N.get(X); - BF->addExecutionMode(BM->add( - new SPIRVExecutionMode(BF, static_cast(EMode), X))); - } break; + case spv::ExecutionModeSubgroupsPerWorkgroup: + AddSingleArgExecutionMode(static_cast(EMode)); + break; case spv::ExecutionModeNumSIMDWorkitemsINTEL: case spv::ExecutionModeSchedulerTargetFmaxMhzINTEL: case spv::ExecutionModeMaxWorkDimINTEL: case spv::internal::ExecutionModeStreamingInterfaceINTEL: { - if (BM->isAllowedToUseExtension( - ExtensionID::SPV_INTEL_kernel_attributes)) { - unsigned X; - N.get(X); - BF->addExecutionMode(BM->add(new SPIRVExecutionMode( - BF, static_cast(EMode), X))); - BM->addExtension(ExtensionID::SPV_INTEL_kernel_attributes); - BM->addCapability(CapabilityFPGAKernelAttributesINTEL); - } + if (!BM->isAllowedToUseExtension( + ExtensionID::SPV_INTEL_kernel_attributes)) + break; + AddSingleArgExecutionMode(static_cast(EMode)); + BM->addExtension(ExtensionID::SPV_INTEL_kernel_attributes); + BM->addCapability(CapabilityFPGAKernelAttributesINTEL); } break; case spv::ExecutionModeSharedLocalMemorySizeINTEL: { if (!BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_vector_compute)) break; - unsigned SLMSize; - N.get(SLMSize); - BF->addExecutionMode(BM->add(new SPIRVExecutionMode( - BF, static_cast(EMode), SLMSize))); + AddSingleArgExecutionMode(static_cast(EMode)); } break; case spv::ExecutionModeNamedBarrierCountINTEL: { if (!BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_vector_compute)) @@ -4664,12 +4658,14 @@ bool LLVMToSPIRVBase::transExecutionMode() { case spv::ExecutionModeSignedZeroInfNanPreserve: case spv::ExecutionModeRoundingModeRTE: case spv::ExecutionModeRoundingModeRTZ: { - if (!BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_float_controls)) - break; - unsigned TargetWidth; - N.get(TargetWidth); - BF->addExecutionMode(BM->add(new SPIRVExecutionMode( - BF, static_cast(EMode), TargetWidth))); + if (BM->isAllowedToUseVersion(VersionNumber::SPIRV_1_4)) { + BM->setMinSPIRVVersion(VersionNumber::SPIRV_1_4); + AddSingleArgExecutionMode(static_cast(EMode)); + } else if (BM->isAllowedToUseExtension( + ExtensionID::SPV_KHR_float_controls)) { + BM->addExtension(ExtensionID::SPV_KHR_float_controls); + AddSingleArgExecutionMode(static_cast(EMode)); + } } break; case spv::ExecutionModeRoundingModeRTPINTEL: case spv::ExecutionModeRoundingModeRTNINTEL: @@ -4678,10 +4674,7 @@ bool LLVMToSPIRVBase::transExecutionMode() { if (!BM->isAllowedToUseExtension( ExtensionID::SPV_INTEL_float_controls2)) break; - unsigned TargetWidth; - N.get(TargetWidth); - BF->addExecutionMode(BM->add(new SPIRVExecutionMode( - BF, static_cast(EMode), TargetWidth))); + AddSingleArgExecutionMode(static_cast(EMode)); } break; case spv::internal::ExecutionModeFastCompositeKernelINTEL: { if (BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_fast_composite)) diff --git a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDecorate.h b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDecorate.h index 9ed8fdc136fb9..a8ee19b6d5a27 100644 --- a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDecorate.h +++ b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDecorate.h @@ -94,6 +94,8 @@ class SPIRVDecorateGeneric : public SPIRVAnnotationGeneric { case DecorationMaxByteOffset: return static_cast(VersionNumber::SPIRV_1_1); + case DecorationUserSemantic: + return static_cast(VersionNumber::SPIRV_1_4); default: return static_cast(VersionNumber::SPIRV_1_0); @@ -127,9 +129,6 @@ class SPIRVDecorate : public SPIRVDecorateGeneric { llvm::Optional getRequiredExtension() const override { switch (static_cast(Dec)) { - case DecorationNoSignedWrap: - case DecorationNoUnsignedWrap: - return ExtensionID::SPV_KHR_no_integer_wrap_decoration; case DecorationRegisterINTEL: case DecorationMemoryINTEL: case DecorationNumbanksINTEL: diff --git a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVEntry.h b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVEntry.h index 6c94c27a1f8e0..d4df50267e881 100644 --- a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVEntry.h +++ b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVEntry.h @@ -843,12 +843,6 @@ class SPIRVCapability : public SPIRVEntryNoId { llvm::Optional getRequiredExtension() const override { switch (static_cast(Kind)) { - case CapabilityDenormPreserve: - case CapabilityDenormFlushToZero: - case CapabilitySignedZeroInfNanPreserve: - case CapabilityRoundingModeRTE: - case CapabilityRoundingModeRTZ: - return ExtensionID::SPV_KHR_float_controls; case CapabilityRoundToInfinityINTEL: case CapabilityFloatingPointModeINTEL: case CapabilityFunctionFloatControlINTEL: diff --git a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVValue.cpp b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVValue.cpp index 3b466f05fabbd..6879b2e2552ae 100644 --- a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVValue.cpp +++ b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVValue.cpp @@ -75,45 +75,10 @@ bool SPIRVValue::hasNoSignedWrap() const { return hasDecorate(DecorationNoSignedWrap); } -void SPIRVValue::setNoSignedWrap(bool HasNoSignedWrap) { - if (!HasNoSignedWrap) { - eraseDecorate(DecorationNoSignedWrap); - } - if (Module->isAllowedToUseExtension( - ExtensionID::SPV_KHR_no_integer_wrap_decoration)) { - // NoSignedWrap decoration is available only if it is allowed to use SPIR-V - // 1.4 or if SPV_KHR_no_integer_wrap_decoration extension is allowed - // FIXME: update this 'if' to include check for SPIR-V 1.4 once translator - // support this version - addDecorate(new SPIRVDecorate(DecorationNoSignedWrap, this)); - SPIRVDBG(spvdbgs() << "Set nsw for obj " << Id << "\n") - } else { - SPIRVDBG(spvdbgs() << "Skip setting nsw for obj " << Id << "\n") - } -} - bool SPIRVValue::hasNoUnsignedWrap() const { return hasDecorate(DecorationNoUnsignedWrap); } -void SPIRVValue::setNoUnsignedWrap(bool HasNoUnsignedWrap) { - if (!HasNoUnsignedWrap) { - eraseDecorate(DecorationNoUnsignedWrap); - return; - } - if (Module->isAllowedToUseExtension( - ExtensionID::SPV_KHR_no_integer_wrap_decoration)) { - // NoUnsignedWrap decoration is available only if it is allowed to use - // SPIR-V 1.4 or if SPV_KHR_no_integer_wrap_decoration extension is allowed - // FIXME: update this 'if' to include check for SPIR-V 1.4 once translator - // support this version - addDecorate(new SPIRVDecorate(DecorationNoUnsignedWrap, this)); - SPIRVDBG(spvdbgs() << "Set nuw for obj " << Id << "\n") - } else { - SPIRVDBG(spvdbgs() << "Skip setting nuw for obj " << Id << "\n") - } -} - void SPIRVValue::setFPFastMathMode(SPIRVWord M) { if (M == 0) { eraseDecorate(DecorationFPFastMathMode); @@ -124,6 +89,39 @@ void SPIRVValue::setFPFastMathMode(SPIRVWord M) { << "\n") } +template +void SPIRVValue::setNoIntegerDecorationWrap(bool HasNoIntegerWrap) { + if (!HasNoIntegerWrap) { + eraseDecorate(NoIntegerWrapDecoration); + return; + } + // NoSignedWrap and NoUnsignedWrap decorations are available only if it is + // allowed to use SPIR-V 1.4 or if SPV_KHR_no_integer_wrap_decoration + // extension is enabled +#ifdef _SPIRVDBG + const std::string InstStr = + NoIntegerWrapDecoration == DecorationNoSignedWrap ? "nsw" : "nuw"; +#endif // _SPIRVDBG + if (Module->isAllowedToUseVersion(VersionNumber::SPIRV_1_4)) { + Module->setMinSPIRVVersion(VersionNumber::SPIRV_1_4); + addDecorate(new SPIRVDecorate(NoIntegerWrapDecoration, this)); + SPIRVDBG(spvdbgs() << "Set " << InstStr << " for obj " << Id << "\n") + } else if (Module->isAllowedToUseExtension( + ExtensionID::SPV_KHR_no_integer_wrap_decoration)) { + Module->addExtension(ExtensionID::SPV_KHR_no_integer_wrap_decoration); + addDecorate(new SPIRVDecorate(NoIntegerWrapDecoration, this)); + SPIRVDBG(spvdbgs() << "Set " << InstStr << " for obj " << Id << "\n") + } else { + SPIRVDBG(spvdbgs() << "Skip setting " << InstStr << " for obj " << Id + << "\n") + } +} + +template void +SPIRVValue::setNoIntegerDecorationWrap(bool); +template void +SPIRVValue::setNoIntegerDecorationWrap(bool); + template void SPIRVConstantBase::setWords(const uint64_t *TheValue) { assert(TheValue && "Nullptr value"); diff --git a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVValue.h b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVValue.h index 4afe4b7598e95..f60bc0a98d2ac 100644 --- a/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVValue.h +++ b/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVValue.h @@ -98,8 +98,10 @@ class SPIRVValue : public SPIRVEntry { void setAlignment(SPIRVWord); void setVolatile(bool IsVolatile); - void setNoSignedWrap(bool HasNoSignedWrap); - void setNoUnsignedWrap(bool HasNoUnsignedWrap); + + template + void setNoIntegerDecorationWrap(bool HasNoIntegerWrap); + void setFPFastMathMode(SPIRVWord FPFastMathMode); void validate() const override { diff --git a/llvm-spirv/test/exec_mode_float_control_khr.ll b/llvm-spirv/test/exec_mode_float_control_khr.ll index e1b1768995e4e..11430a8822dac 100644 --- a/llvm-spirv/test/exec_mode_float_control_khr.ll +++ b/llvm-spirv/test/exec_mode_float_control_khr.ll @@ -1,7 +1,13 @@ ; RUN: llvm-as %s -o %t.bc -; RUN: llvm-spirv %t.bc -o %t.spv --spirv-ext=+SPV_KHR_float_controls +; RUN: llvm-spirv %t.bc -o %t.spv --spirv-max-version=1.1 --spirv-ext=+SPV_KHR_float_controls ; RUN: llvm-spirv %t.spv -o %t.spt --to-text -; RUN: FileCheck %s --input-file %t.spt -check-prefix=SPV +; RUN: FileCheck %s --input-file %t.spt -check-prefixes=SPV,SPVEXT +; RUN: llvm-spirv %t.bc -o %t.spv --spirv-max-version=1.4 +; RUN: llvm-spirv %t.spv -o %t.spt --to-text +; RUN: FileCheck %s --input-file %t.spt -check-prefixes=SPV,SPV14 +; RUN: llvm-spirv %t.bc -o %t.spv --spirv-max-version=1.1 +; RUN: llvm-spirv %t.spv -o %t.spt --to-text +; RUN: FileCheck %s --input-file %t.spt -check-prefix=SPV-NEGATIVE ; ModuleID = 'float_control.bc' source_filename = "float_control.cpp" @@ -44,6 +50,10 @@ entry: !spirv.EntryPoint = !{} !spirv.ExecutionMode = !{!15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !28, !29} +; SPVEXT-DAG: Extension "SPV_KHR_float_controls" +; SPV14-NOT: Extension "SPV_KHR_float_controls" +; SPV-NEGATIVE-NOT: Extension "SPV_KHR_float_controls" + ; SPV-DAG: EntryPoint {{[0-9]+}} [[KERNEL0:[0-9]+]] "k_float_controls_0" ; SPV-DAG: EntryPoint {{[0-9]+}} [[KERNEL1:[0-9]+]] "k_float_controls_1" ; SPV-DAG: EntryPoint {{[0-9]+}} [[KERNEL2:[0-9]+]] "k_float_controls_2" diff --git a/llvm-spirv/test/transcoding/LoopUnroll.ll b/llvm-spirv/test/transcoding/LoopUnroll.ll index 244f062440788..7d367faabe75d 100644 --- a/llvm-spirv/test/transcoding/LoopUnroll.ll +++ b/llvm-spirv/test/transcoding/LoopUnroll.ll @@ -42,6 +42,13 @@ ; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV ; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.rev.bc ; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefixes=CHECK-LLVM +; RUN: llvm-spirv %t.bc -o %t.spv --spirv-max-version=1.1 +; RUN: llvm-spirv -to-text %t.spv -o %t.spt +; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV-NEGATIVE + +; Check SPIR-V versions in a format magic number + version +; CHECK-SPIRV: 119734787 66560 +; CHECK-SPIRV-NEGATIVE: 119734787 65536 target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" target triple = "spir64" @@ -115,6 +122,7 @@ while.cond: ; preds = %if.end, %if.then, % ; Per SPIRV spec p3.23 "Unroll" loop control = 0x1 ; CHECK-SPIRV: LoopMerge [[#MERGEBLOCK:]] [[#CONTINUE:]] 256 8 ; CHECK-SPIRV: BranchConditional [[#]] [[#]] [[#MERGEBLOCK]] +; CHECK-SPIRV-NEGATIVE-NOT: LoopMerge {{.*}} 256 br i1 %cmp, label %while.body, label %while.end while.body: ; preds = %while.cond diff --git a/llvm-spirv/test/transcoding/NoSignedUnsignedWrap.ll b/llvm-spirv/test/transcoding/NoSignedUnsignedWrap.ll index 6e2ea2f665be9..7795e9e964bc8 100644 --- a/llvm-spirv/test/transcoding/NoSignedUnsignedWrap.ll +++ b/llvm-spirv/test/transcoding/NoSignedUnsignedWrap.ll @@ -8,10 +8,15 @@ ; Positive tests: ; ; RUN: llvm-as %s -o %t.bc -; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_KHR_no_integer_wrap_decoration -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV -; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_KHR_no_integer_wrap_decoration -o %t.spv +; RUN: llvm-spirv %t.bc --spirv-max-version=1.1 --spirv-ext=+SPV_KHR_no_integer_wrap_decoration -spirv-text -o - | FileCheck %s --check-prefixes=CHECK-SPIRV,CHECK-SPIRV-EXT +; RUN: llvm-spirv %t.bc --spirv-max-version=1.1 --spirv-ext=+SPV_KHR_no_integer_wrap_decoration -o %t.spv ; RUN: spirv-val %t.spv -; RUN: llvm-spirv -r %t.spv --spirv-ext=+SPV_KHR_no_integer_wrap_decoration -o %t.rev.bc +; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv --spirv-max-version=1.1 --spirv-ext=+SPV_KHR_no_integer_wrap_decoration -o %t.rev.bc +; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM +; RUN: llvm-spirv %t.bc --spirv-max-version=1.4 -spirv-text -o - | FileCheck %s --check-prefixes=CHECK-SPIRV,CHECK-SPIRV-NOEXT +; RUN: llvm-spirv %t.bc --spirv-max-version=1.4 -o %t.spv +; RUN: spirv-val %t.spv +; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv --spirv-max-version=1.4 -o %t.rev.bc ; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM ; ; During consumption, any SPIR-V extension must be accepted by default @@ -21,29 +26,29 @@ ; ; Negative tests: ; -; Check that translator is able to reject SPIR-V if extension is disallowed -; -; RUN: not llvm-spirv -r %t.spv --spirv-ext=-SPV_KHR_no_integer_wrap_decoration -o - 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID-SPIRV +; Check that translator is able to skip nsw/nuw attributes if extension is +; disabled implicitly or explicitly and if max SPIR-V version is lower then 1.4 ; -; Check that translator is able to skip nsw/nuw attributes if extension is disabled implicitly or explicitly -; -; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV-NOEXT -; RUN: llvm-spirv %t.bc -o %t.spv -; RUN: llvm-spirv -r %t.spv -o %t.rev.bc -; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM-NOEXT +; RUN: llvm-spirv %t.bc --spirv-max-version=1.1 -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV-NEGATIVE +; RUN: llvm-spirv --spirv-max-version=1.1 %t.bc -o %t.spv +; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.rev.bc +; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM-NEGATIVE ; -; RUN: llvm-spirv %t.bc --spirv-ext=-SPV_KHR_no_integer_wrap_decoration -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV-NOEXT -; RUN: llvm-spirv %t.bc --spirv-ext=-SPV_KHR_no_integer_wrap_decoration -o %t.spv -; RUN: llvm-spirv -r %t.spv -o %t.rev.bc -; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM-NOEXT +; RUN: llvm-spirv %t.bc --spirv-max-version=1.1 --spirv-ext=-SPV_KHR_no_integer_wrap_decoration -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV-NEGATIVE +; RUN: llvm-spirv %t.bc --spirv-max-version=1.1 --spirv-ext=-SPV_KHR_no_integer_wrap_decoration -o %t.spv +; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.rev.bc +; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM-NEGATIVE -; CHECK-SPIRV: Extension "SPV_KHR_no_integer_wrap_decoration" +; Check SPIR-V versions in a format magic number + version +; CHECK-SPIRV-EXT: 119734787 65536 +; CHECK-SPIRV-EXT: Extension "SPV_KHR_no_integer_wrap_decoration" +; CHECK-SPIRV-NOEXT: 119734787 66560 ; CHECK-SPIRV-DAG: Decorate {{[0-9]+}} NoSignedWrap ; CHECK-SPIRV-DAG: Decorate {{[0-9]+}} NoUnsignedWrap ; -; CHECK-SPIRV-NOEXT-NOT: Extension "SPV_KHR_no_integer_wrap_decoration" -; CHECK-SPIRV-NOEXT-NOT: Decorate {{[0-9]+}} NoSignedWrap -; CHECK-SPIRV-NOEXT-NOT: Decorate {{[0-9]+}} NoUnsignedWrap +; CHECK-SPIRV-NEGATIVE-NOT: Extension "SPV_KHR_no_integer_wrap_decoration" +; CHECK-SPIRV-NEGATIVE-NOT: Decorate {{[0-9]+}} NoSignedWrap +; CHECK-SPIRV-NEGATIVE-NOT: Decorate {{[0-9]+}} NoUnsignedWrap ; ; CHECK-INVALID-SPIRV: input SPIR-V module uses extension 'SPV_KHR_no_integer_wrap_decoration' which were disabled @@ -55,7 +60,7 @@ define spir_func i32 @square(i16 zeroext %a) local_unnamed_addr #0 { entry: %conv = zext i16 %a to i32 ; CHECK-LLVM: mul nuw nsw - ; CHECK-LLVM-NOEXT: mul i32 + ; CHECK-LLVM-NEGATIVE: mul i32 %mul = mul nuw nsw i32 %conv, %conv ret i32 %mul } diff --git a/llvm-spirv/test/transcoding/SPV_INTEL_vector_compute/exec_mode_float_control.ll b/llvm-spirv/test/transcoding/SPV_INTEL_vector_compute/exec_mode_float_control.ll index b80993a93e1f6..91a80fcd98920 100644 --- a/llvm-spirv/test/transcoding/SPV_INTEL_vector_compute/exec_mode_float_control.ll +++ b/llvm-spirv/test/transcoding/SPV_INTEL_vector_compute/exec_mode_float_control.ll @@ -1,11 +1,15 @@ ; RUN: llvm-as %s -o %t.bc -; RUN: llvm-spirv %t.bc -o %t.spv --spirv-ext=+SPV_INTEL_vector_compute,+SPV_KHR_float_controls,+SPV_INTEL_float_controls2 +; RUN: llvm-spirv %t.bc -o %t.spv --spirv-max-version=1.1 --spirv-ext=+SPV_INTEL_vector_compute,+SPV_KHR_float_controls,+SPV_INTEL_float_controls2 ; RUN: llvm-spirv %t.spv -o %t.spt --to-text ; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.bc ; RUN: llvm-dis %t.bc -o %t.ll -; RUN: FileCheck %s --input-file %t.spt -check-prefix=SPV +; RUN: FileCheck %s --input-file %t.spt -check-prefixes=SPV,SPVEXT ; RUN: FileCheck %s --input-file %t.ll -check-prefix=LLVM +; RUN: llvm-spirv %t.bc -o %t.spv --spirv-max-version=1.4 --spirv-ext=+SPV_INTEL_vector_compute,+SPV_INTEL_float_controls2 +; RUN: llvm-spirv %t.spv -o %t.spt --to-text +; RUN: FileCheck %s --input-file %t.spt -check-prefixes=SPV,SPV14 + ; ModuleID = 'float_control.bc' source_filename = "float_control.cpp" @@ -13,7 +17,8 @@ target datalayout = "e-p:64:64-i64:64-n8:16:32" target triple = "spir" -; SPV-DAG: Extension "SPV_KHR_float_controls" +; SPVEXT-DAG: Extension "SPV_KHR_float_controls" +; SPV14-NOT: Extension "SPV_KHR_float_controls" ; SPV-DAG: Extension "SPV_INTEL_float_controls2" ; LLVM-DAG: @k_rte{{[^a-zA-Z0-9_][^#]*}}#[[K_RTE:[0-9]+]] diff --git a/llvm-spirv/test/transcoding/annotate_attribute.ll b/llvm-spirv/test/transcoding/annotate_attribute.ll index 61825db4b33f6..86acf80abb521 100644 --- a/llvm-spirv/test/transcoding/annotate_attribute.ll +++ b/llvm-spirv/test/transcoding/annotate_attribute.ll @@ -10,6 +10,9 @@ ; RUN: llvm-as %s -o %t.bc ; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_fpga_memory_accesses,+SPV_INTEL_fpga_memory_attributes -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV +; Check SPIR-V versions in a format magic number + version +; CHECK-SPIRV: 119734787 66560 + ; CHECK-SPIRV-DAG: Decorate {{[0-9]+}} UserSemantic "42" ; CHECK-SPIRV-DAG: Decorate {{[0-9]+}} UserSemantic "bar" ; CHECK-SPIRV-DAG: Decorate {{[0-9]+}} UserSemantic "{FOO}" diff --git a/llvm-spirv/test/transcoding/block_w_struct_return.cl b/llvm-spirv/test/transcoding/block_w_struct_return.cl index b0c8a5896fb67..5ade1539617a7 100644 --- a/llvm-spirv/test/transcoding/block_w_struct_return.cl +++ b/llvm-spirv/test/transcoding/block_w_struct_return.cl @@ -1,18 +1,19 @@ // RUN: %clang_cc1 -triple spir -cl-std=cl2.0 -disable-llvm-passes -fdeclare-opencl-builtins -finclude-default-header %s -emit-llvm-bc -o %t.bc -no-opaque-pointers - -// RUN: llvm-spirv --spirv-max-version=1.1 %t.bc -spirv-text -o - | FileCheck %s --check-prefixes=CHECK-SPIRV -// RUN: llvm-spirv --spirv-max-version=1.1 %t.bc -o %t.spirv1.1.spv -// RUN: spirv-val --target-env spv1.1 %t.spirv1.1.spv -// RUN: llvm-spirv -r -emit-opaque-pointers %t.spirv1.1.spv -o %t.rev.bc -// RUN: llvm-dis %t.rev.bc -// RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM - -// RUN: llvm-spirv --spirv-max-version=1.4 %t.bc -spirv-text -o - | FileCheck %s --check-prefixes=CHECK-SPIRV -// RUN: llvm-spirv --spirv-max-version=1.4 %t.bc -o %t.spirv1.4.spv -// RUN: spirv-val --target-env spv1.4 %t.spirv1.4.spv -// RUN: llvm-spirv -r -emit-opaque-pointers %t.spirv1.4.spv -o %t.rev.bc -// RUN: llvm-dis %t.rev.bc -// RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM +// TODO: currently max version is limited to 1.1 for this test. Issues here +// that the SPIR-V module generated for blocks is invalid for versions starting +// from 1.4, spirv-val is failing with: +// error: line 63: Interface variable id <13> is used by entry point +// 'block_kernel' id <24>, but is not listed as an interface +// %__block_literal_global = OpVariable %_ptr_CrossWorkgroup__struct_10 +// CrossWorkgroup %11 +// details can be found in: +// – Public issue #35: OpEntryPoint must list all global variables in the +// interface. Additionally, duplication in the list is not allowed. +// RUN: llvm-spirv --spirv-max-version=1.1 %t.bc -spirv-text -o %t.spv.txt +// RUN: FileCheck < %t.spv.txt %s --check-prefix=CHECK-SPIRV +// RUN: llvm-spirv --spirv-max-version=1.1 %t.bc -o %t.spv +// RUN: spirv-val %t.spv +// RUN: llvm-spirv -r %t.spv -o %t.rev.bc kernel void block_ret_struct(__global int* res) { @@ -31,6 +32,13 @@ kernel void block_ret_struct(__global int* res) res[tid] = kernelBlock(aa).a - 6; } +// CHECK-SPIRV1_4: EntryPoint 6 [[#]] "block_ret_struct" [[#InterdaceId1:]] [[#InterdaceId2:]] +// CHECK-SPIRV1_4: Name [[#InterdaceId1]] "__block_literal_global" +// CHECK-SPIRV1_4: Name [[#InterdaceId2]] "__spirv_BuiltInGlobalInvocationId" + +// CHECK-SPIRV1_1: EntryPoint 6 [[#]] "block_ret_struct" [[#InterdaceId1:]] +// CHECK-SPIRV1_1: Name [[#InterdaceId1]] "__spirv_BuiltInGlobalInvocationId" + // CHECK-SPIRV: Name [[BlockInv:[0-9]+]] "__block_ret_struct_block_invoke" // CHECK-SPIRV: 4 TypeInt [[IntTy:[0-9]+]] 32 diff --git a/llvm-spirv/test/transcoding/global_block.cl b/llvm-spirv/test/transcoding/global_block.cl index 22c869f7fbc47..3048518b018b4 100644 --- a/llvm-spirv/test/transcoding/global_block.cl +++ b/llvm-spirv/test/transcoding/global_block.cl @@ -4,16 +4,20 @@ // removed // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -cl-std=CL2.0 -x cl %s -emit-llvm-bc -o %t.bc -no-opaque-pointers - +// TODO: currently max version is limited to 1.1 for this test. Issues here +// that the SPIR-V module generated for blocks is invalid for versions starting +// from 1.4, spirv-val is failing with: +// error: line 63: Interface variable id <13> is used by entry point +// 'block_kernel' id <24>, but is not listed as an interface +// %__block_literal_global = OpVariable %_ptr_CrossWorkgroup__struct_10 +// CrossWorkgroup %11 +// details can be found in: +// – Public issue #35: OpEntryPoint must list all global variables in the +// interface. Additionally, duplication in the list is not allowed. // RUN: llvm-spirv --spirv-max-version=1.1 %t.bc -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV -// RUN: llvm-spirv --spirv-max-version=1.1 %t.bc -o %t.spirv1.1.spv -// RUN: spirv-val --target-env spv1.1 %t.spirv1.1.spv -// RUN: llvm-spirv -r -emit-opaque-pointers %t.spirv1.1.spv -o - | llvm-dis | FileCheck %s --check-prefix=CHECK-LLVM - -// RUN: llvm-spirv --spirv-max-version=1.4 %t.bc -spirv-text -o - | FileCheck %s --check-prefixes=CHECK-SPIRV -// RUN: llvm-spirv --spirv-max-version=1.4 %t.bc -o %t.spirv1.4.spv -// RUN: spirv-val --target-env spv1.4 %t.spirv1.4.spv -// RUN: llvm-spirv -r -emit-opaque-pointers %t.spirv1.4.spv -o - | llvm-dis | FileCheck %s --check-prefix=CHECK-LLVM +// RUN: llvm-spirv --spirv-max-version=1.1 %t.bc -o %t.spv +// RUN: spirv-val %t.spv +// RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o - | llvm-dis | FileCheck %s --check-prefix=CHECK-LLVM kernel void block_kernel(__global int* res) { typedef int (^block_t)(int);