Skip to content

Commit 593ff10

Browse files
author
Alexander Johnston
committed
[SPIRV] ensure OpDpdx/yCoarse aren't produced in opencl
1 parent 994c99b commit 593ff10

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3105,6 +3105,13 @@ bool SPIRVInstructionSelector::selectDpdCoarse(Register ResVReg,
31053105
const SPIRVType *ResType,
31063106
MachineInstr &I,
31073107
const unsigned DPdOpCode) const {
3108+
if (!STI.isShader()) {
3109+
std::string DiagMsg;
3110+
raw_string_ostream OS(DiagMsg);
3111+
I.print(OS, true, false, false, false);
3112+
DiagMsg += " is only supported in shaders.\n";
3113+
report_fatal_error(DiagMsg.c_str(), false);
3114+
}
31083115
// If the arg/result types are half then we need to wrap the instr in
31093116
// conversions to float
31103117
// This case occurs because a half arg/result is legal in HLSL but not spirv.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o /dev/null 2>&1 | FileCheck %s
2+
; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o /dev/null 2>&1 | FileCheck %s
3+
4+
; CHECK: LLVM ERROR: %{{.*}} = G_INTRINSIC intrinsic(@llvm.spv.ddx.coarse), %{{.*}} is only supported in shaders.
5+
6+
define noundef float @ddx_coarse(float noundef %a) {
7+
entry:
8+
%spv.ddx.coarse = call float @llvm.spv.ddx.coarse.f32(float %a)
9+
ret float %spv.ddx.coarse
10+
}
11+
12+
declare float @llvm.spv.ddx.coarse.f32(float)
13+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o /dev/null 2>&1 | FileCheck %s
2+
; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o /dev/null 2>&1 | FileCheck %s
3+
4+
; CHECK: LLVM ERROR: %{{.*}} = G_INTRINSIC intrinsic(@llvm.spv.ddy.coarse), %{{.*}} is only supported in shaders.
5+
6+
define noundef float @ddy_coarse(float noundef %a) {
7+
entry:
8+
%spv.ddy.coarse = call float @llvm.spv.ddy.coarse.f32(float %a)
9+
ret float %spv.ddy.coarse
10+
}
11+
12+
declare float @llvm.spv.ddy.coarse.f32(float)
13+

0 commit comments

Comments
 (0)