Skip to content

Commit b346464

Browse files
committed
Add hlsl spirv and dxil backend tests.
1 parent 7b49c7c commit b346464

File tree

8 files changed

+111
-28
lines changed

8 files changed

+111
-28
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = ±in
665665
T __builtin_elementwise_bitreverse(T x) return the integer represented after reversing the bits of x integer types
666666
T __builtin_elementwise_exp(T x) returns the base-e exponential, e^x, of the specified value floating point types
667667
T __builtin_elementwise_exp2(T x) returns the base-2 exponential, 2^x, of the specified value floating point types
668-
668+
669669
T __builtin_elementwise_sqrt(T x) return the square root of a floating-point number floating point types
670670
T __builtin_elementwise_roundeven(T x) round x to the nearest integer value in floating point format, floating point types
671671
rounding halfway cases to even (that is, to the nearest value

clang/test/CodeGenHLSL/builtins/tan.hlsl

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,58 @@
1-
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
1+
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
22
// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
3-
// RUN: -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
4-
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
5-
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
6-
// RUN: -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
7-
8-
// CHECK: define noundef half @
9-
// CHECK: call half @llvm.tan.f16(
10-
// NO_HALF: define noundef float @"?test_tan_half@@YA$halff@$halff@@Z"(
11-
// NO_HALF: call float @llvm.tan.f32(
3+
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
4+
// RUN: --check-prefixes=CHECK,NATIVE_HALF
5+
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
6+
// RUN: spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \
7+
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
8+
9+
// CHECK-LABEL: test_tan_half
10+
// NATIVE_HALF: call half @llvm.tan.f16
11+
// NO_HALF: call float @llvm.tan.f32
1212
half test_tan_half ( half p0 ) {
1313
return tan ( p0 );
1414
}
15-
// CHECK: define noundef <2 x half> @
16-
// CHECK: call <2 x half> @llvm.tan.v2f16
17-
// NO_HALF: define noundef <2 x float> @"?test_tan_float2@@YAT?$__vector@M$01@__clang@@T12@@Z"(
18-
// NO_HALF: call <2 x float> @llvm.tan.v2f32(
15+
16+
// CHECK-LABEL: test_tan_half2
17+
// NATIVE_HALF: call <2 x half> @llvm.tan.v2f16
18+
// NO_HALF: call <2 x float> @llvm.tan.v2f32
1919
half2 test_tan_half2 ( half2 p0 ) {
2020
return tan ( p0 );
2121
}
22-
// CHECK: define noundef <3 x half> @
23-
// CHECK: call <3 x half> @llvm.tan.v3f16
24-
// NO_HALF: define noundef <3 x float> @"?test_tan_float3@@YAT?$__vector@M$02@__clang@@T12@@Z"(
25-
// NO_HALF: call <3 x float> @llvm.tan.v3f32(
22+
23+
// CHECK-LABEL: test_tan_half3
24+
// NATIVE_HALF: call <3 x half> @llvm.tan.v3f16
25+
// NO_HALF: call <3 x float> @llvm.tan.v3f32
2626
half3 test_tan_half3 ( half3 p0 ) {
2727
return tan ( p0 );
2828
}
29-
// CHECK: define noundef <4 x half> @
30-
// CHECK: call <4 x half> @llvm.tan.v4f16
31-
// NO_HALF: define noundef <4 x float> @"?test_tan_float4@@YAT?$__vector@M$03@__clang@@T12@@Z"(
32-
// NO_HALF: call <4 x float> @llvm.tan.v4f32(
29+
30+
// CHECK-LABEL: test_tan_half4
31+
// NATIVE_HALF: call <4 x half> @llvm.tan.v4f16
32+
// NO_HALF: call <4 x float> @llvm.tan.v4f32
3333
half4 test_tan_half4 ( half4 p0 ) {
3434
return tan ( p0 );
3535
}
3636

37-
// CHECK: define noundef float @
38-
// CHECK: call float @llvm.tan.f32(
37+
// CHECK-LABEL: test_tan_float
38+
// CHECK: call float @llvm.tan.f32
3939
float test_tan_float ( float p0 ) {
4040
return tan ( p0 );
4141
}
42-
// CHECK: define noundef <2 x float> @
42+
43+
// CHECK-LABEL: test_tan_float2
4344
// CHECK: call <2 x float> @llvm.tan.v2f32
4445
float2 test_tan_float2 ( float2 p0 ) {
4546
return tan ( p0 );
4647
}
47-
// CHECK: define noundef <3 x float> @
48+
49+
// CHECK-LABEL: test_tan_float3
4850
// CHECK: call <3 x float> @llvm.tan.v3f32
4951
float3 test_tan_float3 ( float3 p0 ) {
5052
return tan ( p0 );
5153
}
52-
// CHECK: define noundef <4 x float> @
54+
55+
// CHECK-LABEL: test_tan_float4
5356
// CHECK: call <4 x float> @llvm.tan.v4f32
5457
float4 test_tan_float4 ( float4 p0 ) {
5558
return tan ( p0 );

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// 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_sin
1010
// 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_sqrt
1111
// 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_roundeven
12+
// 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
1213
// 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
1314

1415
double2 test_double_builtin(double2 p0) {

llvm/lib/Target/DirectX/DXIL.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ def Cos : DXILOpMapping<12, unary, int_cos,
266266
def Sin : DXILOpMapping<13, unary, int_sin,
267267
"Returns sine(theta) for theta in radians.",
268268
[llvm_halforfloat_ty, LLVMMatchType<0>]>;
269+
def Tan : DXILOpMapping<14, unary, int_tan,
270+
"Returns tangent(theta) for theta in radians.",
271+
[llvm_halforfloat_ty, LLVMMatchType<0>]>;
269272
def Exp2 : DXILOpMapping<21, unary, int_exp2,
270273
"Returns the base 2 exponential, or 2**x, of the specified value."
271274
"exp2(x) = 2**x.",

llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ SPIRVLegalizerInfo::SPIRVLegalizerInfo(const SPIRVSubtarget &ST) {
277277
G_FCEIL,
278278
G_FCOS,
279279
G_FSIN,
280+
G_FTAN,
280281
G_FSQRT,
281282
G_FFLOOR,
282283
G_FRINT,

llvm/test/CodeGen/DirectX/tan.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: opt -S -dxil-op-lower < %s | FileCheck %s
2+
3+
; Make sure dxil operation function calls for tan are generated for float and half.
4+
5+
define noundef float @tan_float(float noundef %a) #0 {
6+
entry:
7+
; CHECK:call float @dx.op.unary.f32(i32 14, float %{{.*}})
8+
%elt.tan = call float @llvm.tan.f32(float %a)
9+
ret float %elt.tan
10+
}
11+
12+
define noundef half @tan_half(half noundef %a) #0 {
13+
entry:
14+
; CHECK:call half @dx.op.unary.f16(i32 14, half %{{.*}})
15+
%elt.tan = call half @llvm.tan.f16(half %a)
16+
ret half %elt.tan
17+
}
18+
19+
declare half @llvm.tan.f16(half)
20+
declare float @llvm.tan.f32(float)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: not opt -S -dxil-op-lower %s 2>&1 | FileCheck %s
2+
3+
; DXIL operation tan does not support double overload type
4+
; CHECK: LLVM ERROR: Invalid Overload
5+
6+
define noundef double @tan_double(double noundef %a) #0 {
7+
entry:
8+
%1 = call double @llvm.tan.f64(double %a)
9+
ret double %1
10+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
; RUN: llc -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+
; CHECK-DAG: %[[#float_32:]] = OpTypeFloat 32
6+
; CHECK-DAG: %[[#float_16:]] = OpTypeFloat 16
7+
; CHECK-DAG: %[[#vec4_float_32:]] = OpTypeVector %[[#float_32]] 4
8+
; CHECK-DAG: %[[#vec4_float_16:]] = OpTypeVector %[[#float_16]] 4
9+
10+
define noundef float @tan_float(float noundef %a) {
11+
entry:
12+
; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#]]
13+
; CHECK: %[[#]] = OpExtInst %[[#float_32]] %[[#op_ext_glsl]] Tan %[[#arg0]]
14+
%elt.tan = call float @llvm.tan.f32(float %a)
15+
ret float %elt.tan
16+
}
17+
18+
define noundef half @tan_half(half noundef %a) {
19+
entry:
20+
; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#]]
21+
; CHECK: %[[#]] = OpExtInst %[[#float_16]] %[[#op_ext_glsl]] Tan %[[#arg0]]
22+
%elt.tan = call half @llvm.tan.f16(half %a)
23+
ret half %elt.tan
24+
}
25+
26+
define noundef <4 x float> @tan_float4(<4 x float> noundef %a) {
27+
entry:
28+
; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#]]
29+
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_32]] %[[#op_ext_glsl]] Tan %[[#arg0]]
30+
%elt.tan = call <4 x float> @llvm.tan.v4f32(<4 x float> %a)
31+
ret <4 x float> %elt.tan
32+
}
33+
34+
define noundef <4 x half> @tan_half4(<4 x half> noundef %a) {
35+
entry:
36+
; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#]]
37+
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_16]] %[[#op_ext_glsl]] Tan %[[#arg0]]
38+
%elt.tan = call <4 x half> @llvm.tan.v4f16(<4 x half> %a)
39+
ret <4 x half> %elt.tan
40+
}
41+
42+
declare half @llvm.tan.f16(half)
43+
declare float @llvm.tan.f32(float)
44+
declare <4 x half> @llvm.tan.v4f16(<4 x half>)
45+
declare <4 x float> @llvm.tan.v4f32(<4 x float>)

0 commit comments

Comments
 (0)