Issue |
123847
|
Summary |
[HLSL] Add checks to the SPIRVInstructionSelector's `selectExtInst` functions for SPIR-V extended instruction set availability
|
Labels |
new issue
|
Assignees |
|
Reporter |
Icohedron
|
Certain SPIR-V instructions are supported only with the [OpenCL extended instruction set](https://registry.khronos.org/SPIR-V/specs/unified1/OpenCL.ExtendedInstructionSet.100.html) but not the [GLSL extended instruction set](https://registry.khronos.org/SPIR-V/specs/unified1/GLSL.std.450.html), and vice-versa.
For example, the `reflect` instruction is supported in GLSL, but not OpenCL. Without adding a check that the extended instruction set is usable by the current SPIR-V target, the compiler will simply crash when attempting to select `G_INTRINSIC intrinsic(@llvm.spv.reflect)` in an OpenCL SPIR-V target.
#122992 implements the check as follows in `llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp`:
```c++
bool SPIRVInstructionSelector::selectExtInst(Register ResVReg,
const SPIRVType *ResType,
MachineInstr &I,
GL::GLSLExtInst GLInst) const {
if (!STI.canUseExtInstSet(
SPIRV::InstructionSet::InstructionSet::GLSL_std_450)) {
std::string DiagMsg;
raw_string_ostream OS(DiagMsg);
I.print(OS, true, false, false, false);
DiagMsg += " is only supported with the GLSL extended instruction set.\n";
report_fatal_error(DiagMsg.c_str(), false);
}
return selectExtInst(ResVReg, ResType, I,
{{SPIRV::InstructionSet::GLSL_std_450, GLInst}});
}
```
There should be similar checks made for the other overloaded versions of the `selectExtInst` to keep things consistent.
```c++
bool selectExtInst(Register ResVReg, const SPIRVType *ResType,
MachineInstr &I, CL::OpenCLExtInst CLInst) const;
bool selectExtInst(Register ResVReg, const SPIRVType *ResType,
MachineInstr &I, CL::OpenCLExtInst CLInst,
GL::GLSLExtInst GLInst) const;
bool selectExtInst(Register ResVReg, const SPIRVType *ResType,
MachineInstr &I, const ExtInstList &ExtInsts) const;
```
A non-exhaustive list of OpenCL-only instructions:
- `vstoren`
- `vloadn`
- `shuffle`
(Note: AFAIK, these OpenCL-only instructions do not have corresponding HLSL intrinsics. I am not sure if there are any OpenCL-only instructions that have a direct [HLSL intrinsic](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-intrinsic-functions) equivalent.)
A non-exhaustive list of GLSL-only instructions:
- `Reflect`
- `Refract`
- `FaceForward`
A full list of exclusive instructions may be constructed by comparing the [OpenCL extended instruction set](https://registry.khronos.org/SPIR-V/specs/unified1/OpenCL.ExtendedInstructionSet.100.html) and [GLSL extended instruction set](https://registry.khronos.org/SPIR-V/specs/unified1/GLSL.std.450.html) specifications.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs