Skip to content

Commit c9b1f1c

Browse files
authored
[HLSL] standardize builtin unit tests (#83340)
This PR brings best practices mentioned to me on other prs and adds them to the existing builtin tests. Note to reviewers: I put this up in two commits because the clang-format changes is making it hard to tell what actually changed. use the first commit to check for correctness.
1 parent 489eadd commit c9b1f1c

File tree

13 files changed

+421
-779
lines changed

13 files changed

+421
-779
lines changed
Lines changed: 43 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,93 @@
11
// RUN: %clang_cc1 -std=hlsl2021 -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
3+
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
4+
// RUN: --check-prefixes=CHECK,NATIVE_HALF
45
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
56
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
6-
// RUN: -o - | FileCheck %s --check-prefix=NO_HALF
7+
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
78

89
using hlsl::abs;
910

1011
#ifdef __HLSL_ENABLE_16_BIT
11-
// CHECK: define noundef i16 @
12-
// CHECK: call i16 @llvm.abs.i16(
13-
int16_t test_abs_int16_t ( int16_t p0 ) {
14-
return abs ( p0 );
15-
}
16-
// CHECK: define noundef <2 x i16> @
17-
// CHECK: call <2 x i16> @llvm.abs.v2i16(
18-
int16_t2 test_abs_int16_t2 ( int16_t2 p0 ) {
19-
return abs ( p0 );
20-
}
21-
// CHECK: define noundef <3 x i16> @
22-
// CHECK: call <3 x i16> @llvm.abs.v3i16(
23-
int16_t3 test_abs_int16_t3 ( int16_t3 p0 ) {
24-
return abs ( p0 );
25-
}
26-
// CHECK: define noundef <4 x i16> @
27-
// CHECK: call <4 x i16> @llvm.abs.v4i16(
28-
int16_t4 test_abs_int16_t4 ( int16_t4 p0 ) {
29-
return abs ( p0 );
30-
}
12+
// NATIVE_HALF: define noundef i16 @
13+
// NATIVE_HALF: call i16 @llvm.abs.i16(
14+
int16_t test_abs_int16_t(int16_t p0) { return abs(p0); }
15+
// NATIVE_HALF: define noundef <2 x i16> @
16+
// NATIVE_HALF: call <2 x i16> @llvm.abs.v2i16(
17+
int16_t2 test_abs_int16_t2(int16_t2 p0) { return abs(p0); }
18+
// NATIVE_HALF: define noundef <3 x i16> @
19+
// NATIVE_HALF: call <3 x i16> @llvm.abs.v3i16(
20+
int16_t3 test_abs_int16_t3(int16_t3 p0) { return abs(p0); }
21+
// NATIVE_HALF: define noundef <4 x i16> @
22+
// NATIVE_HALF: call <4 x i16> @llvm.abs.v4i16(
23+
int16_t4 test_abs_int16_t4(int16_t4 p0) { return abs(p0); }
3124
#endif // __HLSL_ENABLE_16_BIT
3225

33-
// CHECK: define noundef half @
34-
// CHECK: call half @llvm.fabs.f16(
26+
// NATIVE_HALF: define noundef half @
27+
// NATIVE_HALF: call half @llvm.fabs.f16(
3528
// NO_HALF: define noundef float @"?test_abs_half@@YA$halff@$halff@@Z"(
3629
// NO_HALF: call float @llvm.fabs.f32(float %0)
37-
half test_abs_half ( half p0 ) {
38-
return abs ( p0 );
39-
}
40-
// CHECK: define noundef <2 x half> @
41-
// CHECK: call <2 x half> @llvm.fabs.v2f16(
30+
half test_abs_half(half p0) { return abs(p0); }
31+
// NATIVE_HALF: define noundef <2 x half> @
32+
// NATIVE_HALF: call <2 x half> @llvm.fabs.v2f16(
4233
// NO_HALF: define noundef <2 x float> @"?test_abs_half2@@YAT?$__vector@$halff@$01@__clang@@T12@@Z"(
4334
// NO_HALF: call <2 x float> @llvm.fabs.v2f32(
44-
half2 test_abs_half2 ( half2 p0 ) {
45-
return abs ( p0 );
46-
}
47-
// CHECK: define noundef <3 x half> @
48-
// CHECK: call <3 x half> @llvm.fabs.v3f16(
35+
half2 test_abs_half2(half2 p0) { return abs(p0); }
36+
// NATIVE_HALF: define noundef <3 x half> @
37+
// NATIVE_HALF: call <3 x half> @llvm.fabs.v3f16(
4938
// NO_HALF: define noundef <3 x float> @"?test_abs_half3@@YAT?$__vector@$halff@$02@__clang@@T12@@Z"(
5039
// NO_HALF: call <3 x float> @llvm.fabs.v3f32(
51-
half3 test_abs_half3 ( half3 p0 ) {
52-
return abs ( p0 );
53-
}
54-
// CHECK: define noundef <4 x half> @
55-
// CHECK: call <4 x half> @llvm.fabs.v4f16(
40+
half3 test_abs_half3(half3 p0) { return abs(p0); }
41+
// NATIVE_HALF: define noundef <4 x half> @
42+
// NATIVE_HALF: call <4 x half> @llvm.fabs.v4f16(
5643
// NO_HALF: define noundef <4 x float> @"?test_abs_half4@@YAT?$__vector@$halff@$03@__clang@@T12@@Z"(
5744
// NO_HALF: call <4 x float> @llvm.fabs.v4f32(
58-
half4 test_abs_half4 ( half4 p0 ) {
59-
return abs ( p0 );
60-
}
45+
half4 test_abs_half4(half4 p0) { return abs(p0); }
6146
// CHECK: define noundef i32 @
6247
// CHECK: call i32 @llvm.abs.i32(
63-
// NO_HALF: define noundef i32 @"?test_abs_int@@YAHH@Z"
64-
int test_abs_int ( int p0 ) {
65-
return abs ( p0 );
66-
}
48+
int test_abs_int(int p0) { return abs(p0); }
6749
// CHECK: define noundef <2 x i32> @
6850
// CHECK: call <2 x i32> @llvm.abs.v2i32(
69-
int2 test_abs_int2 ( int2 p0 ) {
70-
return abs ( p0 );
71-
}
51+
int2 test_abs_int2(int2 p0) { return abs(p0); }
7252
// CHECK: define noundef <3 x i32> @
7353
// CHECK: call <3 x i32> @llvm.abs.v3i32(
74-
int3 test_abs_int3 ( int3 p0 ) {
75-
return abs ( p0 );
76-
}
54+
int3 test_abs_int3(int3 p0) { return abs(p0); }
7755
// CHECK: define noundef <4 x i32> @
7856
// CHECK: call <4 x i32> @llvm.abs.v4i32(
79-
int4 test_abs_int4 ( int4 p0 ) {
80-
return abs ( p0 );
81-
}
57+
int4 test_abs_int4(int4 p0) { return abs(p0); }
8258
// CHECK: define noundef float @
8359
// CHECK: call float @llvm.fabs.f32(
84-
float test_abs_float ( float p0 ) {
85-
return abs ( p0 );
86-
}
60+
float test_abs_float(float p0) { return abs(p0); }
8761
// CHECK: define noundef <2 x float> @
8862
// CHECK: call <2 x float> @llvm.fabs.v2f32(
89-
float2 test_abs_float2 ( float2 p0 ) {
90-
return abs ( p0 );
91-
}
63+
float2 test_abs_float2(float2 p0) { return abs(p0); }
9264
// CHECK: define noundef <3 x float> @
9365
// CHECK: call <3 x float> @llvm.fabs.v3f32(
94-
float3 test_abs_float3 ( float3 p0 ) {
95-
return abs ( p0 );
96-
}
66+
float3 test_abs_float3(float3 p0) { return abs(p0); }
9767
// CHECK: define noundef <4 x float> @
9868
// CHECK: call <4 x float> @llvm.fabs.v4f32(
99-
float4 test_abs_float4 ( float4 p0 ) {
100-
return abs ( p0 );
101-
}
69+
float4 test_abs_float4(float4 p0) { return abs(p0); }
10270
// CHECK: define noundef i64 @
10371
// CHECK: call i64 @llvm.abs.i64(
104-
int64_t test_abs_int64_t ( int64_t p0 ) {
105-
return abs ( p0 );
106-
}
72+
int64_t test_abs_int64_t(int64_t p0) { return abs(p0); }
10773
// CHECK: define noundef <2 x i64> @
10874
// CHECK: call <2 x i64> @llvm.abs.v2i64(
109-
int64_t2 test_abs_int64_t2 ( int64_t2 p0 ) {
110-
return abs ( p0 );
111-
}
75+
int64_t2 test_abs_int64_t2(int64_t2 p0) { return abs(p0); }
11276
// CHECK: define noundef <3 x i64> @
11377
// CHECK: call <3 x i64> @llvm.abs.v3i64(
114-
int64_t3 test_abs_int64_t3 ( int64_t3 p0 ) {
115-
return abs ( p0 );
116-
}
78+
int64_t3 test_abs_int64_t3(int64_t3 p0) { return abs(p0); }
11779
// CHECK: define noundef <4 x i64> @
11880
// CHECK: call <4 x i64> @llvm.abs.v4i64(
119-
int64_t4 test_abs_int64_t4 ( int64_t4 p0 ) {
120-
return abs ( p0 );
121-
}
81+
int64_t4 test_abs_int64_t4(int64_t4 p0) { return abs(p0); }
12282
// CHECK: define noundef double @
12383
// CHECK: call double @llvm.fabs.f64(
124-
double test_abs_double ( double p0 ) {
125-
return abs ( p0 );
126-
}
84+
double test_abs_double(double p0) { return abs(p0); }
12785
// CHECK: define noundef <2 x double> @
12886
// CHECK: call <2 x double> @llvm.fabs.v2f64(
129-
double2 test_abs_double2 ( double2 p0 ) {
130-
return abs ( p0 );
131-
}
87+
double2 test_abs_double2(double2 p0) { return abs(p0); }
13288
// CHECK: define noundef <3 x double> @
13389
// CHECK: call <3 x double> @llvm.fabs.v3f64(
134-
double3 test_abs_double3 ( double3 p0 ) {
135-
return abs ( p0 );
136-
}
90+
double3 test_abs_double3(double3 p0) { return abs(p0); }
13791
// CHECK: define noundef <4 x double> @
13892
// CHECK: call <4 x double> @llvm.fabs.v4f64(
139-
double4 test_abs_double4 ( double4 p0 ) {
140-
return abs ( p0 );
141-
}
93+
double4 test_abs_double4(double4 p0) { return abs(p0); }
Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,56 @@
11
// RUN: %clang_cc1 -std=hlsl2021 -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
3+
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
4+
// RUN: --check-prefixes=CHECK,NATIVE_HALF
45
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
56
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
6-
// RUN: -o - | FileCheck %s --check-prefix=NO_HALF
7+
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
78

89
using hlsl::ceil;
910

10-
// CHECK: define noundef half @
11-
// CHECK: call half @llvm.ceil.f16(
11+
// NATIVE_HALF: define noundef half @
12+
// NATIVE_HALF: call half @llvm.ceil.f16(
1213
// NO_HALF: define noundef float @"?test_ceil_half@@YA$halff@$halff@@Z"(
1314
// NO_HALF: call float @llvm.ceil.f32(float %0)
14-
half test_ceil_half ( half p0 ) {
15-
return ceil ( p0 );
16-
}
17-
// CHECK: define noundef <2 x half> @
18-
// CHECK: call <2 x half> @llvm.ceil.v2f16(
15+
half test_ceil_half(half p0) { return ceil(p0); }
16+
// NATIVE_HALF: define noundef <2 x half> @
17+
// NATIVE_HALF: call <2 x half> @llvm.ceil.v2f16(
1918
// NO_HALF: define noundef <2 x float> @"?test_ceil_half2@@YAT?$__vector@$halff@$01@__clang@@T12@@Z"(
2019
// NO_HALF: call <2 x float> @llvm.ceil.v2f32(
21-
half2 test_ceil_half2 ( half2 p0 ) {
22-
return ceil ( p0 );
23-
}
24-
// CHECK: define noundef <3 x half> @
25-
// CHECK: call <3 x half> @llvm.ceil.v3f16(
20+
half2 test_ceil_half2(half2 p0) { return ceil(p0); }
21+
// NATIVE_HALF: define noundef <3 x half> @
22+
// NATIVE_HALF: call <3 x half> @llvm.ceil.v3f16(
2623
// NO_HALF: define noundef <3 x float> @"?test_ceil_half3@@YAT?$__vector@$halff@$02@__clang@@T12@@Z"(
2724
// NO_HALF: call <3 x float> @llvm.ceil.v3f32(
28-
half3 test_ceil_half3 ( half3 p0 ) {
29-
return ceil ( p0 );
30-
}
31-
// CHECK: define noundef <4 x half> @
32-
// CHECK: call <4 x half> @llvm.ceil.v4f16(
25+
half3 test_ceil_half3(half3 p0) { return ceil(p0); }
26+
// NATIVE_HALF: define noundef <4 x half> @
27+
// NATIVE_HALF: call <4 x half> @llvm.ceil.v4f16(
3328
// NO_HALF: define noundef <4 x float> @"?test_ceil_half4@@YAT?$__vector@$halff@$03@__clang@@T12@@Z"(
3429
// NO_HALF: call <4 x float> @llvm.ceil.v4f32(
35-
half4 test_ceil_half4 ( half4 p0 ) {
36-
return ceil ( p0 );
37-
}
30+
half4 test_ceil_half4(half4 p0) { return ceil(p0); }
3831

3932
// CHECK: define noundef float @
4033
// CHECK: call float @llvm.ceil.f32(
41-
float test_ceil_float ( float p0 ) {
42-
return ceil ( p0 );
43-
}
34+
float test_ceil_float(float p0) { return ceil(p0); }
4435
// CHECK: define noundef <2 x float> @
4536
// CHECK: call <2 x float> @llvm.ceil.v2f32(
46-
float2 test_ceil_float2 ( float2 p0 ) {
47-
return ceil ( p0 );
48-
}
37+
float2 test_ceil_float2(float2 p0) { return ceil(p0); }
4938
// CHECK: define noundef <3 x float> @
5039
// CHECK: call <3 x float> @llvm.ceil.v3f32(
51-
float3 test_ceil_float3 ( float3 p0 ) {
52-
return ceil ( p0 );
53-
}
40+
float3 test_ceil_float3(float3 p0) { return ceil(p0); }
5441
// CHECK: define noundef <4 x float> @
5542
// CHECK: call <4 x float> @llvm.ceil.v4f32(
56-
float4 test_ceil_float4 ( float4 p0 ) {
57-
return ceil ( p0 );
58-
}
43+
float4 test_ceil_float4(float4 p0) { return ceil(p0); }
5944

6045
// CHECK: define noundef double @
6146
// CHECK: call double @llvm.ceil.f64(
62-
double test_ceil_double ( double p0 ) {
63-
return ceil ( p0 );
64-
}
47+
double test_ceil_double(double p0) { return ceil(p0); }
6548
// CHECK: define noundef <2 x double> @
6649
// CHECK: call <2 x double> @llvm.ceil.v2f64(
67-
double2 test_ceil_double2 ( double2 p0 ) {
68-
return ceil ( p0 );
69-
}
50+
double2 test_ceil_double2(double2 p0) { return ceil(p0); }
7051
// CHECK: define noundef <3 x double> @
7152
// CHECK: call <3 x double> @llvm.ceil.v3f64(
72-
double3 test_ceil_double3 ( double3 p0 ) {
73-
return ceil ( p0 );
74-
}
53+
double3 test_ceil_double3(double3 p0) { return ceil(p0); }
7554
// CHECK: define noundef <4 x double> @
7655
// CHECK: call <4 x double> @llvm.ceil.v4f64(
77-
double4 test_ceil_double4 ( double4 p0 ) {
78-
return ceil ( p0 );
79-
}
56+
double4 test_ceil_double4(double4 p0) { return ceil(p0); }
Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,41 @@
11
// RUN: %clang_cc1 -std=hlsl2021 -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
3+
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
4+
// RUN: --check-prefixes=CHECK,NATIVE_HALF
45
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
56
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
6-
// RUN: -o - | FileCheck %s --check-prefix=NO_HALF
7+
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
78

8-
// CHECK: define noundef half @
9-
// CHECK: call half @llvm.cos.f16(
10-
// NO_HALF: define noundef float @"?test_cos_half@@YA$halff@$halff@@Z"(
9+
// NATIVE_HALF: define noundef half @
10+
// NATIVE_HALF: call half @llvm.cos.f16(
11+
// NO_HALF: define noundef float @"?test_cos_half
1112
// NO_HALF: call float @llvm.cos.f32(
12-
half test_cos_half ( half p0 ) {
13-
return cos ( p0 );
14-
}
15-
// CHECK: define noundef <2 x half> @
16-
// CHECK: call <2 x half> @llvm.cos.v2f16
17-
// NO_HALF: define noundef <2 x float> @"?test_cos_float2@@YAT?$__vector@M$01@__clang@@T12@@Z"(
13+
half test_cos_half(half p0) { return cos(p0); }
14+
// NATIVE_HALF: define noundef <2 x half> @
15+
// NATIVE_HALF: call <2 x half> @llvm.cos.v2f16
16+
// NO_HALF: define noundef <2 x float> @"?test_cos_half2
1817
// NO_HALF: call <2 x float> @llvm.cos.v2f32(
19-
half2 test_cos_half2 ( half2 p0 ) {
20-
return cos ( p0 );
21-
}
22-
// CHECK: define noundef <3 x half> @
23-
// CHECK: call <3 x half> @llvm.cos.v3f16
24-
// NO_HALF: define noundef <3 x float> @"?test_cos_float3@@YAT?$__vector@M$02@__clang@@T12@@Z"(
18+
half2 test_cos_half2(half2 p0) { return cos(p0); }
19+
// NATIVE_HALF: define noundef <3 x half> @
20+
// NATIVE_HALF: call <3 x half> @llvm.cos.v3f16
21+
// NO_HALF: define noundef <3 x float> @"?test_cos_half3
2522
// NO_HALF: call <3 x float> @llvm.cos.v3f32(
26-
half3 test_cos_half3 ( half3 p0 ) {
27-
return cos ( p0 );
28-
}
29-
// CHECK: define noundef <4 x half> @
30-
// CHECK: call <4 x half> @llvm.cos.v4f16
31-
// NO_HALF: define noundef <4 x float> @"?test_cos_float4@@YAT?$__vector@M$03@__clang@@T12@@Z"(
23+
half3 test_cos_half3(half3 p0) { return cos(p0); }
24+
// NATIVE_HALF: define noundef <4 x half> @
25+
// NATIVE_HALF: call <4 x half> @llvm.cos.v4f16
26+
// NO_HALF: define noundef <4 x float> @"?test_cos_half4
3227
// NO_HALF: call <4 x float> @llvm.cos.v4f32(
33-
half4 test_cos_half4 ( half4 p0 ) {
34-
return cos ( p0 );
35-
}
28+
half4 test_cos_half4(half4 p0) { return cos(p0); }
3629

37-
// CHECK: define noundef float @
30+
// CHECK: define noundef float @"?test_cos_float
3831
// CHECK: call float @llvm.cos.f32(
39-
float test_cos_float ( float p0 ) {
40-
return cos ( p0 );
41-
}
42-
// CHECK: define noundef <2 x float> @
32+
float test_cos_float(float p0) { return cos(p0); }
33+
// CHECK: define noundef <2 x float> @"?test_cos_float2
4334
// CHECK: call <2 x float> @llvm.cos.v2f32
44-
float2 test_cos_float2 ( float2 p0 ) {
45-
return cos ( p0 );
46-
}
47-
// CHECK: define noundef <3 x float> @
35+
float2 test_cos_float2(float2 p0) { return cos(p0); }
36+
// CHECK: define noundef <3 x float> @"?test_cos_float3
4837
// CHECK: call <3 x float> @llvm.cos.v3f32
49-
float3 test_cos_float3 ( float3 p0 ) {
50-
return cos ( p0 );
51-
}
52-
// CHECK: define noundef <4 x float> @
38+
float3 test_cos_float3(float3 p0) { return cos(p0); }
39+
// CHECK: define noundef <4 x float> @"?test_cos_float4
5340
// CHECK: call <4 x float> @llvm.cos.v4f32
54-
float4 test_cos_float4 ( float4 p0 ) {
55-
return cos ( p0 );
56-
}
41+
float4 test_cos_float4(float4 p0) { return cos(p0); }

0 commit comments

Comments
 (0)