Skip to content

Commit 461d513

Browse files
committed
[HLSL] Implementation the degrees intrinsic
- add degrees builtin - link degrees api in hlsl_intrinsics.h - add degrees intrinsic to IntrinsicDirectX.td - add degrees intrinsic to IntrinsicSPIRV.td - add lowering from clang builtin to dx/spv intrinsics in CGBuiltin.cpp - add semantic checks to SemaHLSL.cpp - add expansion of directx intrinsic to llvm fmul for DirectX in DXILIntrinsicExpansion.cpp - add mapping to spir-v intrinsic in SPIRVInstructionSelector.cpp - add test coverage: - degrees.hlsl -> check hlsl lowering to dx/spv degrees intrinsics - degrees-errors.hlsl/half-float-only-errors -> check semantic warnings - hlsl-intrinsics/degrees.ll -> check lowering of spir-v degrees intrinsic to SPIR-V backend - DirectX/degrees.ll -> check expansion and scalarization of directx degrees intrinsic to fmul
1 parent e379b4b commit 461d513

File tree

15 files changed

+339
-0
lines changed

15 files changed

+339
-0
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4739,6 +4739,12 @@ def HLSLClamp : LangBuiltin<"HLSL_LANG"> {
47394739
let Prototype = "void(...)";
47404740
}
47414741

4742+
def HLSLDegrees : LangBuiltin<"HLSL_LANG"> {
4743+
let Spellings = ["__builtin_hlsl_elementwise_degrees"];
4744+
let Attributes = [NoThrow, Const];
4745+
let Prototype = "void(...)";
4746+
}
4747+
47424748
def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
47434749
let Spellings = ["__builtin_hlsl_dot"];
47444750
let Attributes = [NoThrow, Const];

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18740,6 +18740,17 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
1874018740
CGM.getHLSLRuntime().getNormalizeIntrinsic(), ArrayRef<Value *>{X},
1874118741
nullptr, "hlsl.normalize");
1874218742
}
18743+
case Builtin::BI__builtin_hlsl_elementwise_degrees: {
18744+
Value *X = EmitScalarExpr(E->getArg(0));
18745+
18746+
assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
18747+
"degree operand must have a float representation");
18748+
18749+
return Builder.CreateIntrinsic(
18750+
/*ReturnType=*/X->getType(),
18751+
CGM.getHLSLRuntime().getDegreesIntrinsic(),
18752+
ArrayRef<Value *>{X}, nullptr, "hlsl.degrees");
18753+
}
1874318754
case Builtin::BI__builtin_hlsl_elementwise_frac: {
1874418755
Value *Op0 = EmitScalarExpr(E->getArg(0));
1874518756
if (!E->getArg(0)->getType()->hasFloatingRepresentation())

clang/lib/CodeGen/CGHLSLRuntime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class CGHLSLRuntime {
7474

7575
GENERATE_HLSL_INTRINSIC_FUNCTION(All, all)
7676
GENERATE_HLSL_INTRINSIC_FUNCTION(Any, any)
77+
GENERATE_HLSL_INTRINSIC_FUNCTION(Degrees, degrees)
7778
GENERATE_HLSL_INTRINSIC_FUNCTION(Frac, frac)
7879
GENERATE_HLSL_INTRINSIC_FUNCTION(Length, length)
7980
GENERATE_HLSL_INTRINSIC_FUNCTION(Lerp, lerp)

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,36 @@ uint64_t3 countbits(uint64_t3);
766766
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_popcount)
767767
uint64_t4 countbits(uint64_t4);
768768

769+
//===----------------------------------------------------------------------===//
770+
// degrees builtins
771+
//===----------------------------------------------------------------------===//
772+
773+
/// \fn T degrees(T x)
774+
/// \brief Converts the specified value from radians to degrees.
775+
/// \param x The specified input value.
776+
777+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
778+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
779+
half degrees(half);
780+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
781+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
782+
half2 degrees(half2);
783+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
784+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
785+
half3 degrees(half3);
786+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
787+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
788+
half4 degrees(half4);
789+
790+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
791+
float degrees(float);
792+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
793+
float2 degrees(float2);
794+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
795+
float3 degrees(float3);
796+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
797+
float4 degrees(float4);
798+
769799
//===----------------------------------------------------------------------===//
770800
// dot product builtins
771801
//===----------------------------------------------------------------------===//

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,7 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
18611861
return true;
18621862
break;
18631863
}
1864+
case Builtin::BI__builtin_hlsl_elementwise_degrees:
18641865
case Builtin::BI__builtin_hlsl_elementwise_rsqrt:
18651866
case Builtin::BI__builtin_hlsl_elementwise_frac: {
18661867
if (CheckFloatOrHalfRepresentations(&SemaRef, TheCall))
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
2+
// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
3+
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
4+
// RUN: --check-prefixes=CHECK,NATIVE_HALF \
5+
// RUN: -DFNATTRS=noundef -DTARGET=dx
6+
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
7+
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
8+
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF \
9+
// RUN: -DFNATTRS=noundef -DTARGET=dx
10+
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
11+
// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \
12+
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
13+
// RUN: --check-prefixes=CHECK,NATIVE_HALF \
14+
// RUN: -DFNATTRS="spir_func noundef" -DTARGET=spv
15+
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
16+
// RUN: spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \
17+
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF \
18+
// RUN: -DFNATTRS="spir_func noundef" -DTARGET=spv
19+
20+
// NATIVE_HALF: define [[FNATTRS]] half @
21+
// NATIVE_HALF: %hlsl.degrees = call half @llvm.[[TARGET]].degrees.f16(
22+
// NATIVE_HALF: ret half %hlsl.degrees
23+
// NO_HALF: define [[FNATTRS]] float @
24+
// NO_HALF: %hlsl.degrees = call float @llvm.[[TARGET]].degrees.f32(
25+
// NO_HALF: ret float %hlsl.degrees
26+
half test_degrees_half(half p0) { return degrees(p0); }
27+
// NATIVE_HALF: define [[FNATTRS]] <2 x half> @
28+
// NATIVE_HALF: %hlsl.degrees = call <2 x half> @llvm.[[TARGET]].degrees.v2f16
29+
// NATIVE_HALF: ret <2 x half> %hlsl.degrees
30+
// NO_HALF: define [[FNATTRS]] <2 x float> @
31+
// NO_HALF: %hlsl.degrees = call <2 x float> @llvm.[[TARGET]].degrees.v2f32(
32+
// NO_HALF: ret <2 x float> %hlsl.degrees
33+
half2 test_degrees_half2(half2 p0) { return degrees(p0); }
34+
// NATIVE_HALF: define [[FNATTRS]] <3 x half> @
35+
// NATIVE_HALF: %hlsl.degrees = call <3 x half> @llvm.[[TARGET]].degrees.v3f16
36+
// NATIVE_HALF: ret <3 x half> %hlsl.degrees
37+
// NO_HALF: define [[FNATTRS]] <3 x float> @
38+
// NO_HALF: %hlsl.degrees = call <3 x float> @llvm.[[TARGET]].degrees.v3f32(
39+
// NO_HALF: ret <3 x float> %hlsl.degrees
40+
half3 test_degrees_half3(half3 p0) { return degrees(p0); }
41+
// NATIVE_HALF: define [[FNATTRS]] <4 x half> @
42+
// NATIVE_HALF: %hlsl.degrees = call <4 x half> @llvm.[[TARGET]].degrees.v4f16
43+
// NATIVE_HALF: ret <4 x half> %hlsl.degrees
44+
// NO_HALF: define [[FNATTRS]] <4 x float> @
45+
// NO_HALF: %hlsl.degrees = call <4 x float> @llvm.[[TARGET]].degrees.v4f32(
46+
// NO_HALF: ret <4 x float> %hlsl.degrees
47+
half4 test_degrees_half4(half4 p0) { return degrees(p0); }
48+
49+
// CHECK: define [[FNATTRS]] float @
50+
// CHECK: %hlsl.degrees = call float @llvm.[[TARGET]].degrees.f32(
51+
// CHECK: ret float %hlsl.degrees
52+
float test_degrees_float(float p0) { return degrees(p0); }
53+
// CHECK: define [[FNATTRS]] <2 x float> @
54+
// CHECK: %hlsl.degrees = call <2 x float> @llvm.[[TARGET]].degrees.v2f32
55+
// CHECK: ret <2 x float> %hlsl.degrees
56+
float2 test_degrees_float2(float2 p0) { return degrees(p0); }
57+
// CHECK: define [[FNATTRS]] <3 x float> @
58+
// CHECK: %hlsl.degrees = call <3 x float> @llvm.[[TARGET]].degrees.v3f32
59+
// CHECK: ret <3 x float> %hlsl.degrees
60+
float3 test_degrees_float3(float3 p0) { return degrees(p0); }
61+
// CHECK: define [[FNATTRS]] <4 x float> @
62+
// CHECK: %hlsl.degrees = call <4 x float> @llvm.[[TARGET]].degrees.v4f32
63+
// CHECK: ret <4 x float> %hlsl.degrees
64+
float4 test_degrees_float4(float4 p0) { return degrees(p0); }
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected
2+
3+
float test_too_few_arg() {
4+
return __builtin_hlsl_elementwise_degrees();
5+
// expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
6+
}
7+
8+
float2 test_too_many_arg(float2 p0) {
9+
return __builtin_hlsl_elementwise_degrees(p0, p0);
10+
// expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
11+
}
12+
13+
float builtin_bool_to_float_type_promotion(bool p1) {
14+
return __builtin_hlsl_elementwise_degrees(p1);
15+
// expected-error@-1 {{passing 'bool' to parameter of incompatible type 'float'}}
16+
}
17+
18+
float builtin_degrees_int_to_float_promotion(int p1) {
19+
return __builtin_hlsl_elementwise_degrees(p1);
20+
// expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}}
21+
}
22+
23+
float2 builtin_degrees_int2_to_float2_promotion(int2 p1) {
24+
return __builtin_hlsl_elementwise_degrees(p1);
25+
// expected-error@-1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}}
26+
}
27+
28+
// builtins are variadic functions and so are subject to DefaultVariadicArgumentPromotion
29+
half builtin_degrees_half_scalar (half p0) {
30+
return __builtin_hlsl_elementwise_degrees(p0);
31+
// expected-error@-1 {{passing 'double' to parameter of incompatible type 'float'}}
32+
}
33+
34+
float builtin_degrees_float_scalar (float p0) {
35+
return __builtin_hlsl_elementwise_degrees(p0);
36+
// expected-error@-1 {{passing 'double' to parameter of incompatible type 'float'}}
37+
}

clang/test/SemaHLSL/BuiltIns/half-float-only-errors.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_tan
1818
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_tanh
1919
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_trunc
20+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -DTEST_FUNC=__builtin_hlsl_elementwise_degrees
2021

2122
double test_double_builtin(double p0) {
2223
return TEST_FUNC(p0);

llvm/include/llvm/IR/IntrinsicsDirectX.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def int_dx_udot :
7070
[IntrNoMem, Commutative] >;
7171

7272
def int_dx_frac : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem]>;
73+
def int_dx_degrees : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty], [IntrNoMem]>;
7374

7475
def int_dx_isinf : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>],
7576
[llvm_anyfloat_ty], [IntrNoMem]>;

llvm/include/llvm/IR/IntrinsicsSPIRV.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ let TargetPrefix = "spv" in {
6161
def int_spv_thread_id : Intrinsic<[llvm_i32_ty], [llvm_i32_ty], [IntrNoMem, IntrWillReturn]>;
6262
def int_spv_all : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_any_ty], [IntrNoMem]>;
6363
def int_spv_any : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_any_ty], [IntrNoMem]>;
64+
def int_spv_degrees : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty], [IntrNoMem]>;
6465
def int_spv_frac : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty], [IntrNoMem]>;
6566
def int_spv_lerp : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty, LLVMMatchType<0>,LLVMMatchType<0>],
6667
[IntrNoMem] >;

llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ static bool isIntrinsicExpansion(Function &F) {
5555
case Intrinsic::dx_any:
5656
case Intrinsic::dx_clamp:
5757
case Intrinsic::dx_uclamp:
58+
case Intrinsic::dx_degrees:
5859
case Intrinsic::dx_lerp:
5960
case Intrinsic::dx_length:
6061
case Intrinsic::dx_normalize:
@@ -444,6 +445,14 @@ static Value *expandClampIntrinsic(CallInst *Orig,
444445
{MaxCall, Max}, nullptr, "dx.min");
445446
}
446447

448+
static Value *expandDegreesIntrinsic(CallInst *Orig) {
449+
Value *X = Orig->getOperand(0);
450+
Type *Ty = X->getType();
451+
IRBuilder<> Builder(Orig);
452+
Value *DegreesRatio = ConstantFP::get(Ty, 180.0 * llvm::numbers::inv_pi);
453+
return Builder.CreateFMul(X, DegreesRatio);
454+
}
455+
447456
static Value *expandSignIntrinsic(CallInst *Orig) {
448457
Value *X = Orig->getOperand(0);
449458
Type *Ty = X->getType();
@@ -500,6 +509,9 @@ static bool expandIntrinsic(Function &F, CallInst *Orig) {
500509
case Intrinsic::dx_clamp:
501510
Result = expandClampIntrinsic(Orig, IntrinsicId);
502511
break;
512+
case Intrinsic::dx_degrees:
513+
Result = expandDegreesIntrinsic(Orig);
514+
break;
503515
case Intrinsic::dx_lerp:
504516
Result = expandLerpIntrinsic(Orig);
505517
break;

llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,6 +2504,8 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg,
25042504
return selectExtInst(ResVReg, ResType, I, CL::mix, GL::FMix);
25052505
case Intrinsic::spv_length:
25062506
return selectExtInst(ResVReg, ResType, I, CL::length, GL::Length);
2507+
case Intrinsic::spv_degrees:
2508+
return selectExtInst(ResVReg, ResType, I, CL::degrees, GL::Degrees);
25072509
case Intrinsic::spv_frac:
25082510
return selectExtInst(ResVReg, ResType, I, CL::fract, GL::Fract);
25092511
case Intrinsic::spv_normalize:

llvm/test/CodeGen/DirectX/degrees.ll

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
; RUN: opt -S -dxil-intrinsic-expansion -scalarizer -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
2+
3+
; Make sure dxil op function calls for degrees are expanded and lowered as fmul for float and half.
4+
5+
define noundef half @degrees_half(half noundef %a) {
6+
; CHECK-LABEL: define noundef half @degrees_half(
7+
; CHECK-SAME: half noundef [[A:%.*]]) {
8+
; CHECK-NEXT: [[ENTRY:.*:]]
9+
; CHECK-NEXT: [[DX_DEGREES1:%.*]] = fmul half [[A]], 0xH5329
10+
; CHECK-NEXT: ret half [[DX_DEGREES1]]
11+
;
12+
entry:
13+
%dx.degrees = call half @llvm.dx.degrees.f16(half %a)
14+
ret half %dx.degrees
15+
}
16+
17+
define noundef float @degrees_float(float noundef %a) #0 {
18+
; CHECK-LABEL: define noundef float @degrees_float(
19+
; CHECK-SAME: float noundef [[A:%.*]]) {
20+
; CHECK-NEXT: [[ENTRY:.*:]]
21+
; CHECK-NEXT: [[DX_DEGREES1:%.*]] = fmul float [[A]], 0x404CA5DC20000000
22+
; CHECK-NEXT: ret float [[DX_DEGREES1]]
23+
;
24+
entry:
25+
%dx.degrees = call float @llvm.dx.degrees.f32(float %a)
26+
ret float %dx.degrees
27+
}
28+
29+
define noundef <4 x float> @degrees_float4(<4 x float> noundef %a) #0 {
30+
; CHECK-LABEL: define noundef <4 x float> @degrees_float4(
31+
; CHECK-SAME: <4 x float> noundef [[A:%.*]]) {
32+
; CHECK-NEXT: [[ENTRY:.*:]]
33+
; CHECK-NEXT: [[A_I0:%.*]] = extractelement <4 x float> [[A]], i64 0
34+
; CHECK-NEXT: [[DOTI04:%.*]] = fmul float [[A_I0]], 0x404CA5DC20000000
35+
; CHECK-NEXT: [[A_I1:%.*]] = extractelement <4 x float> [[A]], i64 1
36+
; CHECK-NEXT: [[DOTI13:%.*]] = fmul float [[A_I1]], 0x404CA5DC20000000
37+
; CHECK-NEXT: [[A_I2:%.*]] = extractelement <4 x float> [[A]], i64 2
38+
; CHECK-NEXT: [[DOTI22:%.*]] = fmul float [[A_I2]], 0x404CA5DC20000000
39+
; CHECK-NEXT: [[A_I3:%.*]] = extractelement <4 x float> [[A]], i64 3
40+
; CHECK-NEXT: [[DOTI31:%.*]] = fmul float [[A_I3]], 0x404CA5DC20000000
41+
; CHECK-NEXT: [[DOTUPTO0:%.*]] = insertelement <4 x float> poison, float [[DOTI04]], i64 0
42+
; CHECK-NEXT: [[DOTUPTO1:%.*]] = insertelement <4 x float> [[DOTUPTO0]], float [[DOTI13]], i64 1
43+
; CHECK-NEXT: [[DOTUPTO2:%.*]] = insertelement <4 x float> [[DOTUPTO1]], float [[DOTI22]], i64 2
44+
; CHECK-NEXT: [[TMP0:%.*]] = insertelement <4 x float> [[DOTUPTO2]], float [[DOTI31]], i64 3
45+
; CHECK-NEXT: ret <4 x float> [[TMP0]]
46+
;
47+
entry:
48+
%2 = call <4 x float> @llvm.dx.degrees.v4f32(<4 x float> %a)
49+
ret <4 x float> %2
50+
}
51+
52+
declare half @llvm.dx.degrees.f16(half)
53+
declare float @llvm.dx.degrees.f32(float)
54+
declare <4 x float> @llvm.dx.degrees.v4f32(<4 x float>)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
; CHECK-DAG: %[[#float_64:]] = OpTypeFloat 64
9+
10+
; CHECK-DAG: %[[#vec4_float_32:]] = OpTypeVector %[[#float_32]] 4
11+
; CHECK-DAG: %[[#vec4_float_16:]] = OpTypeVector %[[#float_16]] 4
12+
; CHECK-DAG: %[[#vec4_float_64:]] = OpTypeVector %[[#float_64]] 4
13+
14+
define noundef float @degrees_float(float noundef %a) {
15+
entry:
16+
; CHECK: %[[#float_32_arg:]] = OpFunctionParameter %[[#float_32]]
17+
; CHECK: %[[#]] = OpExtInst %[[#float_32]] %[[#op_ext_glsl]] Degrees %[[#float_32_arg]]
18+
%elt.degrees = call float @llvm.spv.degrees.f32(float %a)
19+
ret float %elt.degrees
20+
}
21+
22+
define noundef half @degrees_half(half noundef %a) {
23+
entry:
24+
; CHECK: %[[#float_16_arg:]] = OpFunctionParameter %[[#float_16]]
25+
; CHECK: %[[#]] = OpExtInst %[[#float_16]] %[[#op_ext_glsl]] Degrees %[[#float_16_arg]]
26+
%elt.degrees = call half @llvm.spv.degrees.f16(half %a)
27+
ret half %elt.degrees
28+
}
29+
30+
define noundef double @degrees_double(double noundef %a) {
31+
entry:
32+
; CHECK: %[[#float_64_arg:]] = OpFunctionParameter %[[#float_64]]
33+
; CHECK: %[[#]] = OpExtInst %[[#float_64]] %[[#op_ext_glsl]] Degrees %[[#float_64_arg]]
34+
%elt.degrees = call double @llvm.spv.degrees.f64(double %a)
35+
ret double %elt.degrees
36+
}
37+
38+
define noundef <4 x float> @degrees_float_vector(<4 x float> noundef %a) {
39+
entry:
40+
; CHECK: %[[#vec4_float_32_arg:]] = OpFunctionParameter %[[#vec4_float_32]]
41+
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_32]] %[[#op_ext_glsl]] Degrees %[[#vec4_float_32_arg]]
42+
%elt.degrees = call <4 x float> @llvm.spv.degrees.v4f32(<4 x float> %a)
43+
ret <4 x float> %elt.degrees
44+
}
45+
46+
define noundef <4 x half> @degrees_half_vector(<4 x half> noundef %a) {
47+
entry:
48+
; CHECK: %[[#vec4_float_16_arg:]] = OpFunctionParameter %[[#vec4_float_16]]
49+
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_16]] %[[#op_ext_glsl]] Degrees %[[#vec4_float_16_arg]]
50+
%elt.degrees = call <4 x half> @llvm.spv.degrees.v4f16(<4 x half> %a)
51+
ret <4 x half> %elt.degrees
52+
}
53+
54+
define noundef <4 x double> @degrees_double_vector(<4 x double> noundef %a) {
55+
entry:
56+
; CHECK: %[[#vec4_float_64_arg:]] = OpFunctionParameter %[[#vec4_float_64]]
57+
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_64]] %[[#op_ext_glsl]] Degrees %[[#vec4_float_64_arg]]
58+
%elt.degrees = call <4 x double> @llvm.spv.degrees.v4f64(<4 x double> %a)
59+
ret <4 x double> %elt.degrees
60+
}
61+
62+
declare half @llvm.spv.degrees.f16(half)
63+
declare float @llvm.spv.degrees.f32(float)
64+
declare double @llvm.spv.degrees.f64(double)
65+
66+
declare <4 x float> @llvm.spv.degrees.v4f32(<4 x float>)
67+
declare <4 x half> @llvm.spv.degrees.v4f16(<4 x half>)
68+
declare <4 x double> @llvm.spv.degrees.v4f64(<4 x double>)

0 commit comments

Comments
 (0)