Skip to content

Commit c0f9fa3

Browse files
committed
Add check for GLSL extended instruction set use
Certain SPIR-V instructions are only available in the GLSL extended instruction set, such as "Reflect". This commit adds a check to ensure the current SPIR-V target can use the GLSL extended instruction set before selecting an instruction that is only available from the GLSL extended instruction set.
1 parent f9fd109 commit c0f9fa3

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,14 @@ bool SPIRVInstructionSelector::selectExtInst(Register ResVReg,
903903
const SPIRVType *ResType,
904904
MachineInstr &I,
905905
GL::GLSLExtInst GLInst) const {
906+
if (!STI.canUseExtInstSet(
907+
SPIRV::InstructionSet::InstructionSet::GLSL_std_450)) {
908+
std::string DiagMsg;
909+
raw_string_ostream OS(DiagMsg);
910+
I.print(OS, true, false, false, false);
911+
DiagMsg += " is only supported with the GLSL extended instruction set.\n";
912+
report_fatal_error(DiagMsg.c_str(), false);
913+
}
906914
return selectExtInst(ResVReg, ResType, I,
907915
{{SPIRV::InstructionSet::GLSL_std_450, GLInst}});
908916
}
@@ -3032,15 +3040,6 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg,
30323040
case Intrinsic::spv_normalize:
30333041
return selectExtInst(ResVReg, ResType, I, CL::normalize, GL::Normalize);
30343042
case Intrinsic::spv_reflect:
3035-
if (!STI.canUseExtInstSet(
3036-
SPIRV::InstructionSet::InstructionSet::GLSL_std_450)) {
3037-
std::string DiagMsg;
3038-
raw_string_ostream OS(DiagMsg);
3039-
I.print(OS);
3040-
DiagMsg = "Intrinsic selection not supported for this instruction set: " +
3041-
DiagMsg;
3042-
report_fatal_error(DiagMsg.c_str(), false);
3043-
}
30443043
return selectExtInst(ResVReg, ResType, I, GL::Reflect);
30453044
case Intrinsic::spv_rsqrt:
30463045
return selectExtInst(ResVReg, ResType, I, CL::rsqrt, GL::InverseSqrt);

llvm/test/CodeGen/SPIRV/opencl/reflect-error.ll

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,13 @@
33
; RUN: not %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o /dev/null 2>&1 -filetype=obj %}
44
; RUN: not %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o /dev/null 2>&1 -filetype=obj %}
55

6-
; CHECK: LLVM ERROR: Intrinsic selection not supported for this instruction set: %{{.*}} = G_INTRINSIC intrinsic(@llvm.spv.reflect), %{{.*}}, %{{.*}}
7-
8-
define noundef <4 x half> @reflect_half4(<4 x half> noundef %a, <4 x half> noundef %b) {
9-
entry:
10-
%spv.reflect = call <4 x half> @llvm.spv.reflect.f16(<4 x half> %a, <4 x half> %b)
11-
ret <4 x half> %spv.reflect
12-
}
6+
; CHECK: LLVM ERROR: %{{.*}} = G_INTRINSIC intrinsic(@llvm.spv.reflect), %{{.*}}, %{{.*}} is only supported with the GLSL extended instruction set.
137

148
define noundef <4 x float> @reflect_float4(<4 x float> noundef %a, <4 x float> noundef %b) {
159
entry:
1610
%spv.reflect = call <4 x float> @llvm.spv.reflect.f32(<4 x float> %a, <4 x float> %b)
1711
ret <4 x float> %spv.reflect
1812
}
1913

20-
declare <4 x half> @llvm.spv.reflect.f16(<4 x half>, <4 x half>)
2114
declare <4 x float> @llvm.spv.reflect.f32(<4 x float>, <4 x float>)
2215

0 commit comments

Comments
 (0)