Skip to content

Commit b2c615f

Browse files
committed
Reapply "[SPIRV] Add radians intrinsic"
I had too many tabs open and reverted #110800 by mistake, it was supposed to be #110616. This reverts commit dec6fe3.
1 parent dec6fe3 commit b2c615f

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed

llvm/include/llvm/IR/IntrinsicsSPIRV.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,5 @@ let TargetPrefix = "spv" in {
8484
[IntrNoMem, Commutative] >;
8585
def int_spv_wave_is_first_lane : DefaultAttrsIntrinsic<[llvm_i1_ty], [], [IntrConvergent]>;
8686
def int_spv_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_any_ty], [IntrNoMem]>;
87+
def int_spv_radians : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty], [IntrNoMem]>;
8788
}

llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,6 +2537,8 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg,
25372537
}
25382538
case Intrinsic::spv_step:
25392539
return selectExtInst(ResVReg, ResType, I, CL::step, GL::Step);
2540+
case Intrinsic::spv_radians:
2541+
return selectExtInst(ResVReg, ResType, I, CL::radians, GL::Radians);
25402542
// Discard intrinsics which we do not expect to actually represent code after
25412543
// lowering or intrinsics which are not implemented but should not crash when
25422544
// found in a customer's LLVM IR input.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
; CHECK-DAG: %[[#op_ext_glsl:]] = OpExtInstImport "GLSL.std.450"
5+
6+
; CHECK-DAG: %[[#float_32:]] = OpTypeFloat 32
7+
; CHECK-DAG: %[[#float_16:]] = OpTypeFloat 16
8+
9+
; CHECK-DAG: %[[#vec4_float_32:]] = OpTypeVector %[[#float_32]] 4
10+
; CHECK-DAG: %[[#vec4_float_16:]] = OpTypeVector %[[#float_16]] 4
11+
12+
declare half @llvm.spv.radians.f16(half)
13+
declare float @llvm.spv.radians.f32(float)
14+
15+
declare <4 x float> @llvm.spv.radians.v4f32(<4 x float>)
16+
declare <4 x half> @llvm.spv.radians.v4f16(<4 x half>)
17+
18+
define noundef float @radians_float(float noundef %a) {
19+
entry:
20+
; CHECK: %[[#float_32_arg:]] = OpFunctionParameter %[[#float_32]]
21+
; CHECK: %[[#]] = OpExtInst %[[#float_32]] %[[#op_ext_glsl]] Radians %[[#float_32_arg]]
22+
%elt.radians = call float @llvm.spv.radians.f32(float %a)
23+
ret float %elt.radians
24+
}
25+
26+
define noundef half @radians_half(half noundef %a) {
27+
entry:
28+
; CHECK: %[[#float_16_arg:]] = OpFunctionParameter %[[#float_16]]
29+
; CHECK: %[[#]] = OpExtInst %[[#float_16]] %[[#op_ext_glsl]] Radians %[[#float_16_arg]]
30+
%elt.radians = call half @llvm.spv.radians.f16(half %a)
31+
ret half %elt.radians
32+
}
33+
34+
define noundef <4 x float> @radians_float_vector(<4 x float> noundef %a) {
35+
entry:
36+
; CHECK: %[[#vec4_float_32_arg:]] = OpFunctionParameter %[[#vec4_float_32]]
37+
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_32]] %[[#op_ext_glsl]] Radians %[[#vec4_float_32_arg]]
38+
%elt.radians = call <4 x float> @llvm.spv.radians.v4f32(<4 x float> %a)
39+
ret <4 x float> %elt.radians
40+
}
41+
42+
define noundef <4 x half> @radians_half_vector(<4 x half> noundef %a) {
43+
entry:
44+
; CHECK: %[[#vec4_float_16_arg:]] = OpFunctionParameter %[[#vec4_float_16]]
45+
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_16]] %[[#op_ext_glsl]] Radians %[[#vec4_float_16_arg]]
46+
%elt.radians = call <4 x half> @llvm.spv.radians.v4f16(<4 x half> %a)
47+
ret <4 x half> %elt.radians
48+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
2+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
3+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
4+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
5+
6+
; CHECK-DAG: %[[#op_ext_glsl:]] = OpExtInstImport "OpenCL.std"
7+
8+
; CHECK-DAG: %[[#float_32:]] = OpTypeFloat 32
9+
; CHECK-DAG: %[[#float_16:]] = OpTypeFloat 16
10+
11+
; CHECK-DAG: %[[#vec4_float_32:]] = OpTypeVector %[[#float_32]] 4
12+
; CHECK-DAG: %[[#vec4_float_16:]] = OpTypeVector %[[#float_16]] 4
13+
14+
declare half @llvm.spv.radians.f16(half)
15+
declare float @llvm.spv.radians.f32(float)
16+
17+
declare <4 x float> @llvm.spv.radians.v4f32(<4 x float>)
18+
declare <4 x half> @llvm.spv.radians.v4f16(<4 x half>)
19+
20+
define noundef float @radians_float(float noundef %a) {
21+
entry:
22+
; CHECK: %[[#float_32_arg:]] = OpFunctionParameter %[[#float_32]]
23+
; CHECK: %[[#]] = OpExtInst %[[#float_32]] %[[#op_ext_glsl]] radians %[[#float_32_arg]]
24+
%elt.radians = call float @llvm.spv.radians.f32(float %a)
25+
ret float %elt.radians
26+
}
27+
28+
define noundef half @radians_half(half noundef %a) {
29+
entry:
30+
; CHECK: %[[#float_16_arg:]] = OpFunctionParameter %[[#float_16]]
31+
; CHECK: %[[#]] = OpExtInst %[[#float_16]] %[[#op_ext_glsl]] radians %[[#float_16_arg]]
32+
%elt.radians = call half @llvm.spv.radians.f16(half %a)
33+
ret half %elt.radians
34+
}
35+
36+
define noundef <4 x float> @radians_float_vector(<4 x float> noundef %a) {
37+
entry:
38+
; CHECK: %[[#vec4_float_32_arg:]] = OpFunctionParameter %[[#vec4_float_32]]
39+
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_32]] %[[#op_ext_glsl]] radians %[[#vec4_float_32_arg]]
40+
%elt.radians = call <4 x float> @llvm.spv.radians.v4f32(<4 x float> %a)
41+
ret <4 x float> %elt.radians
42+
}
43+
44+
define noundef <4 x half> @radians_half_vector(<4 x half> noundef %a) {
45+
entry:
46+
; CHECK: %[[#vec4_float_16_arg:]] = OpFunctionParameter %[[#vec4_float_16]]
47+
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_16]] %[[#op_ext_glsl]] radians %[[#vec4_float_16_arg]]
48+
%elt.radians = call <4 x half> @llvm.spv.radians.v4f16(<4 x half> %a)
49+
ret <4 x half> %elt.radians
50+
}
51+

0 commit comments

Comments
 (0)