Skip to content

Commit 8082482

Browse files
committed
Add test to verify generation of llvm.spv.saturate.* instructions
Change type check to assert.
1 parent e9fd01b commit 8082482

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18669,8 +18669,8 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
1866918669
}
1867018670
case Builtin::BI__builtin_hlsl_elementwise_saturate: {
1867118671
Value *Op0 = EmitScalarExpr(E->getArg(0));
18672-
if (!E->getArg(0)->getType()->hasFloatingRepresentation())
18673-
llvm_unreachable("saturate operand must have a float representation");
18672+
assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
18673+
"saturate operand must have a float representation");
1867418674
return Builder.CreateIntrinsic(
1867518675
/*ReturnType=*/Op0->getType(),
1867618676
CGM.getHLSLRuntime().getSaturateIntrinsic(), ArrayRef<Value *>{Op0},

clang/test/CodeGenHLSL/builtins/saturate.hlsl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,90 @@
66
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
77
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
88

9+
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
10+
// RUN: spirv-unknown-vulkan-library %s -fnative-half-type \
11+
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
12+
// RUN: --check-prefixes=SPIRV,SPIRV_HALF
13+
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
14+
// RUN: spirv-unknown-vulkan-library %s \
15+
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
16+
// RUN: --check-prefixes=SPIRV,SPIRV_NO_HALF
17+
918
// NATIVE_HALF: define noundef half @
1019
// NATIVE_HALF: call half @llvm.dx.saturate.f16(
1120
// NO_HALF: define noundef float @"?test_saturate_half
1221
// NO_HALF: call float @llvm.dx.saturate.f32(
22+
// SPIRV_HALF: define spir_func noundef half @_Z18test_saturate_halfDh(half
23+
// SPIRV_HALF: call half @llvm.spv.saturate.f16(half
24+
// SPIRV_NO_HALF: define spir_func noundef float @_Z18test_saturate_halfDh(float
25+
// SPIRV_NO_HALF: call float @llvm.spv.saturate.f32(float
1326
half test_saturate_half(half p0) { return saturate(p0); }
1427
// NATIVE_HALF: define noundef <2 x half> @
1528
// NATIVE_HALF: call <2 x half> @llvm.dx.saturate.v2f16
1629
// NO_HALF: define noundef <2 x float> @"?test_saturate_half2
1730
// NO_HALF: call <2 x float> @llvm.dx.saturate.v2f32(
31+
// SPIRV_HALF: define spir_func noundef <2 x half> @_Z19test_saturate_half2Dv2_Dh(
32+
// SPIRV_HALF: call <2 x half> @llvm.spv.saturate.v2f16(<2 x half>
33+
// SPIRV_NO_HALF: define spir_func noundef <2 x float> @_Z19test_saturate_half2Dv2_Dh(<2 x float>
34+
// SPIRV_NO_HALF: call <2 x float> @llvm.spv.saturate.v2f32(<2 x float>
1835
half2 test_saturate_half2(half2 p0) { return saturate(p0); }
1936
// NATIVE_HALF: define noundef <3 x half> @
2037
// NATIVE_HALF: call <3 x half> @llvm.dx.saturate.v3f16
2138
// NO_HALF: define noundef <3 x float> @"?test_saturate_half3
2239
// NO_HALF: call <3 x float> @llvm.dx.saturate.v3f32(
40+
// SPIRV_HALF: define spir_func noundef <3 x half> @_Z19test_saturate_half3Dv3_Dh(
41+
// SPIRV_HALF: call <3 x half> @llvm.spv.saturate.v3f16(<3 x half>
42+
// SPIRV_NO_HALF: define spir_func noundef <3 x float> @_Z19test_saturate_half3Dv3_Dh(<3 x float>
43+
// SPIRV_NO_HALF: call <3 x float> @llvm.spv.saturate.v3f32(<3 x float>
2344
half3 test_saturate_half3(half3 p0) { return saturate(p0); }
2445
// NATIVE_HALF: define noundef <4 x half> @
2546
// NATIVE_HALF: call <4 x half> @llvm.dx.saturate.v4f16
2647
// NO_HALF: define noundef <4 x float> @"?test_saturate_half4
2748
// NO_HALF: call <4 x float> @llvm.dx.saturate.v4f32(
49+
// SPIRV_HALF: define spir_func noundef <4 x half> @_Z19test_saturate_half4Dv4_Dh(
50+
// SPIRV_HALF: call <4 x half> @llvm.spv.saturate.v4f16(<4 x half>
51+
// SPIRV_NO_HALF: define spir_func noundef <4 x float> @_Z19test_saturate_half4Dv4_Dh(<4 x float>
52+
// SPIRV_NO_HALF: call <4 x float> @llvm.spv.saturate.v4f32(<4 x float>
2853
half4 test_saturate_half4(half4 p0) { return saturate(p0); }
2954

3055
// CHECK: define noundef float @"?test_saturate_float
3156
// CHECK: call float @llvm.dx.saturate.f32(
57+
// SPIRV: define spir_func noundef float @_Z19test_saturate_floatf(float
58+
// SPIRV: call float @llvm.spv.saturate.f32(float
3259
float test_saturate_float(float p0) { return saturate(p0); }
3360
// CHECK: define noundef <2 x float> @"?test_saturate_float2
3461
// CHECK: call <2 x float> @llvm.dx.saturate.v2f32
62+
// SPIRV: define spir_func noundef <2 x float> @_Z20test_saturate_float2Dv2_f(<2 x float>
63+
// SPIRV: call <2 x float> @llvm.spv.saturate.v2f32(<2 x float>
3564
float2 test_saturate_float2(float2 p0) { return saturate(p0); }
3665
// CHECK: define noundef <3 x float> @"?test_saturate_float3
3766
// CHECK: call <3 x float> @llvm.dx.saturate.v3f32
67+
// SPIRV: define spir_func noundef <3 x float> @_Z20test_saturate_float3Dv3_f(<3 x float>
68+
// SPIRV: call <3 x float> @llvm.spv.saturate.v3f32(<3 x float>
3869
float3 test_saturate_float3(float3 p0) { return saturate(p0); }
3970
// CHECK: define noundef <4 x float> @"?test_saturate_float4
4071
// CHECK: call <4 x float> @llvm.dx.saturate.v4f32
72+
// SPIRV: define spir_func noundef <4 x float> @_Z20test_saturate_float4Dv4_f(<4 x float>
73+
// SPIRV: call <4 x float> @llvm.spv.saturate.v4f32(<4 x float>
4174
float4 test_saturate_float4(float4 p0) { return saturate(p0); }
4275

4376
// CHECK: define noundef double @
4477
// CHECK: call double @llvm.dx.saturate.f64(
78+
// SPIRV: define spir_func noundef double @_Z20test_saturate_doubled(double
79+
// SPIRV: call double @llvm.spv.saturate.f64(double
4580
double test_saturate_double(double p0) { return saturate(p0); }
4681
// CHECK: define noundef <2 x double> @
4782
// CHECK: call <2 x double> @llvm.dx.saturate.v2f64
83+
// SPIRV: define spir_func noundef <2 x double> @_Z21test_saturate_double2Dv2_d(<2 x double>
84+
// SPIRV: call <2 x double> @llvm.spv.saturate.v2f64(<2 x double>
4885
double2 test_saturate_double2(double2 p0) { return saturate(p0); }
4986
// CHECK: define noundef <3 x double> @
5087
// CHECK: call <3 x double> @llvm.dx.saturate.v3f64
88+
// SPIRV: define spir_func noundef <3 x double> @_Z21test_saturate_double3Dv3_d(<3 x double>
89+
// SPIRV: call <3 x double> @llvm.spv.saturate.v3f64(<3 x double>
5190
double3 test_saturate_double3(double3 p0) { return saturate(p0); }
5291
// CHECK: define noundef <4 x double> @
5392
// CHECK: call <4 x double> @llvm.dx.saturate.v4f64
93+
// SPIRV: define spir_func noundef <4 x double> @_Z21test_saturate_double4Dv4_d(<4 x double>
94+
// SPIRV: call <4 x double> @llvm.spv.saturate.v4f64(<4 x double>
5495
double4 test_saturate_double4(double4 p0) { return saturate(p0); }

0 commit comments

Comments
 (0)