https://github.com/kmpeng updated https://github.com/llvm/llvm-project/pull/215436
>From 9757a2981f53addb787d1c957b131f82fcddf35d Mon Sep 17 00:00:00 2001 From: kmpeng <[email protected]> Date: Mon, 10 Aug 2026 17:06:00 -0700 Subject: [PATCH 1/2] move `degrees` implementation --- clang/include/clang/Basic/Builtins.td | 6 - clang/include/clang/Basic/HLSLIntrinsics.td | 3 +- clang/lib/CodeGen/CGHLSLBuiltins.cpp | 10 -- clang/lib/CodeGen/CGHLSLRuntime.h | 1 - clang/lib/Headers/hlsl/hlsl_detail.h | 2 + .../lib/Headers/hlsl/hlsl_intrinsic_helpers.h | 4 + clang/lib/Sema/SemaHLSL.cpp | 1 - .../CodeGenHLSL/builtins/degrees-builtin.hlsl | 16 --- .../builtins/degrees-overloads.hlsl | 129 +++++++++--------- clang/test/CodeGenHLSL/builtins/degrees.hlsl | 77 ++++------- .../SemaHLSL/BuiltIns/degrees-errors.hlsl | 34 +++-- .../BuiltIns/half-float-only-errors.hlsl | 1 - llvm/include/llvm/IR/IntrinsicsDirectX.td | 1 - .../Target/DirectX/DXILIntrinsicExpansion.cpp | 12 -- llvm/test/CodeGen/DirectX/degrees.ll | 54 -------- 15 files changed, 115 insertions(+), 236 deletions(-) delete mode 100644 clang/test/CodeGenHLSL/builtins/degrees-builtin.hlsl delete mode 100644 llvm/test/CodeGen/DirectX/degrees.ll diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index b67a22ad50689..c3cc70e59e299 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -5653,12 +5653,6 @@ def HLSLClamp : LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } -def HLSLDegrees : LangBuiltin<"HLSL_LANG"> { - let Spellings = ["__builtin_hlsl_elementwise_degrees"]; - let Attributes = [NoThrow, Const, CustomTypeChecking]; - let Prototype = "void(...)"; -} - def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> { let Spellings = ["__builtin_hlsl_dot"]; let Attributes = [NoThrow, Const, CustomTypeChecking]; diff --git a/clang/include/clang/Basic/HLSLIntrinsics.td b/clang/include/clang/Basic/HLSLIntrinsics.td index 2d27728608c77..8557dcdc29b67 100644 --- a/clang/include/clang/Basic/HLSLIntrinsics.td +++ b/clang/include/clang/Basic/HLSLIntrinsics.td @@ -675,12 +675,13 @@ prevision partial derivative of the input value. } // Converts the specified value from radians to degrees. -def hlsl_degrees : HLSLOneArgBuiltin<"degrees", "__builtin_hlsl_elementwise_degrees"> { +def hlsl_degrees : HLSLOneArgDetail<"degrees", "degrees_impl"> { let Doc = [{ \fn T degrees(T x) \brief Converts the specified value from radians to degrees. \param x The specified input value. }]; + let ParamNames = ["x"]; let VaryingTypes = [HalfTy, FloatTy]; let VaryingMatDims = []; } diff --git a/clang/lib/CodeGen/CGHLSLBuiltins.cpp b/clang/lib/CodeGen/CGHLSLBuiltins.cpp index c7d1de29f0651..201fbd7a3e48c 100644 --- a/clang/lib/CodeGen/CGHLSLBuiltins.cpp +++ b/clang/lib/CodeGen/CGHLSLBuiltins.cpp @@ -1140,16 +1140,6 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, CGM.getHLSLRuntime().getNormalizeIntrinsic(), ArrayRef<Value *>{X}, nullptr, "hlsl.normalize"); } - case Builtin::BI__builtin_hlsl_elementwise_degrees: { - Value *X = EmitScalarExpr(E->getArg(0)); - - assert(E->getArg(0)->getType()->hasFloatingRepresentation() && - "degree operand must have a float representation"); - - return Builder.CreateIntrinsic( - /*ReturnType=*/X->getType(), CGM.getHLSLRuntime().getDegreesIntrinsic(), - ArrayRef<Value *>{X}, nullptr, "hlsl.degrees"); - } case Builtin::BI__builtin_hlsl_elementwise_f16tof32: { return handleElementwiseF16ToF32(*this, E); } diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h index 263d6faa8255c..61b114648fdf6 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.h +++ b/clang/lib/CodeGen/CGHLSLRuntime.h @@ -123,7 +123,6 @@ class CGHLSLRuntime { GENERATE_HLSL_INTRINSIC_FUNCTION(All, all) GENERATE_HLSL_INTRINSIC_FUNCTION(Any, any) - GENERATE_HLSL_INTRINSIC_FUNCTION(Degrees, degrees) GENERATE_HLSL_INTRINSIC_FUNCTION(Frac, frac) GENERATE_HLSL_INTRINSIC_FUNCTION(FlattenedThreadIdInGroup, flattened_thread_id_in_group) diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h b/clang/lib/Headers/hlsl/hlsl_detail.h index cda9bfaab8805..cf8655ae19705 100644 --- a/clang/lib/Headers/hlsl/hlsl_detail.h +++ b/clang/lib/Headers/hlsl/hlsl_detail.h @@ -13,6 +13,8 @@ namespace hlsl { namespace __detail { +constexpr double pi = 3.141592653589793L; + template <typename T, typename U> struct is_same { static const bool value = false; }; diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h index 0b6adc66c672a..8b6742ddeec7f 100644 --- a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h @@ -176,6 +176,10 @@ template <typename T> constexpr T fwidth_impl(T input) { #endif } +template <typename T> constexpr T degrees_impl(T Val) { + return Val * (T)(180 / pi); +} + } // namespace __detail } // namespace hlsl diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 3b9d9e4ed964b..cbee175133c3c 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -4434,7 +4434,6 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { return true; break; } - case Builtin::BI__builtin_hlsl_elementwise_degrees: case Builtin::BI__builtin_hlsl_elementwise_radians: case Builtin::BI__builtin_hlsl_elementwise_rsqrt: case Builtin::BI__builtin_hlsl_elementwise_frac: diff --git a/clang/test/CodeGenHLSL/builtins/degrees-builtin.hlsl b/clang/test/CodeGenHLSL/builtins/degrees-builtin.hlsl deleted file mode 100644 index 3098ed242a492..0000000000000 --- a/clang/test/CodeGenHLSL/builtins/degrees-builtin.hlsl +++ /dev/null @@ -1,16 +0,0 @@ -// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -fnative-int16-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s - - -// CHECK-LABEL: builtin_degrees_half -// CHECK: %hlsl.degrees = call reassoc nnan ninf nsz arcp afn half @llvm.dx.degrees.f16(half %{{.*}}) -// CHECK: ret half %hlsl.degrees -half builtin_degrees_half(half p0) { - return __builtin_hlsl_elementwise_degrees(p0); -} - -// CHECK-LABEL: builtin_degrees_float -// CHECK: %hlsl.degrees = call reassoc nnan ninf nsz arcp afn float @llvm.dx.degrees.f32(float %{{.*}}) -// CHECK: ret float %hlsl.degrees -float builtin_degrees_float (float p0) { - return __builtin_hlsl_elementwise_degrees(p0); -} diff --git a/clang/test/CodeGenHLSL/builtins/degrees-overloads.hlsl b/clang/test/CodeGenHLSL/builtins/degrees-overloads.hlsl index 403b953edc65c..e49bd354a97fa 100644 --- a/clang/test/CodeGenHLSL/builtins/degrees-overloads.hlsl +++ b/clang/test/CodeGenHLSL/builtins/degrees-overloads.hlsl @@ -1,137 +1,130 @@ // RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple \ // RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm \ -// RUN: -Wdeprecated-declarations -o - | FileCheck %s --check-prefixes=CHECK \ -// RUN: -DFNATTRS="hidden noundef nofpclass(nan inf)" -DTARGET=dx -// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple \ -// RUN: spirv-unknown-vulkan-library %s -emit-llvm \ -// RUN: -Wdeprecated-declarations -o - | FileCheck %s --check-prefixes=CHECK \ -// RUN: -DFNATTRS="hidden spir_func noundef nofpclass(nan inf)" -DTARGET=spv +// RUN: -Wdeprecated-declarations -o - | FileCheck %s // RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s \ // RUN: -verify -verify-ignore-unexpected=note -// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple spirv-unknown-vulkan-library %s \ -// RUN: -verify -verify-ignore-unexpected=note -// CHECK: define [[FNATTRS]] float @_Z19test_degrees_doubled( +// CHECK-LABEL: test_degrees_double // CHECK: [[CONVI:%.*]] = fptrunc {{.*}} double %{{.*}} to float -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} float @llvm.[[TARGET]].degrees.f32(float [[CONVI]]) -// CHECK: ret float [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn float %{{.*}}, f0x42652EE1 +// CHECK: ret float [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x 64 bit API lowering for degrees is deprecated. Explicitly cast parameters to 32 or 16 bit types.}} float test_degrees_double(double p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <2 x float> @_Z20test_degrees_double2Dv2_d( +// CHECK-LABEL: test_degrees_double2 // CHECK: [[CONVI:%.*]] = fptrunc {{.*}} <2 x double> %{{.*}} to <2 x float> -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} <2 x float> @llvm.[[TARGET]].degrees.v2f32(<2 x float> [[CONVI]]) -// CHECK: ret <2 x float> [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK: ret <2 x float> [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x 64 bit API lowering for degrees is deprecated. Explicitly cast parameters to 32 or 16 bit types.}} float2 test_degrees_double2(double2 p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <3 x float> @_Z20test_degrees_double3Dv3_d( +// CHECK-LABEL: test_degrees_double3 // CHECK: [[CONVI:%.*]] = fptrunc {{.*}} <3 x double> %{{.*}} to <3 x float> -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} <3 x float> @llvm.[[TARGET]].degrees.v3f32(<3 x float> [[CONVI]]) -// CHECK: ret <3 x float> [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK: ret <3 x float> [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x 64 bit API lowering for degrees is deprecated. Explicitly cast parameters to 32 or 16 bit types.}} float3 test_degrees_double3(double3 p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <4 x float> @_Z20test_degrees_double4Dv4_d( +// CHECK-LABEL: test_degrees_double4 // CHECK: [[CONVI:%.*]] = fptrunc {{.*}} <4 x double> %{{.*}} to <4 x float> -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} <4 x float> @llvm.[[TARGET]].degrees.v4f32(<4 x float> [[CONVI]]) -// CHECK: ret <4 x float> [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK: ret <4 x float> [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x 64 bit API lowering for degrees is deprecated. Explicitly cast parameters to 32 or 16 bit types.}} float4 test_degrees_double4(double4 p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] float @_Z16test_degrees_inti( +// CHECK-LABEL: test_degrees_int // CHECK: [[CONVI:%.*]] = sitofp {{.*}} i32 %{{.*}} to float -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} float @llvm.[[TARGET]].degrees.f32(float [[CONVI]]) -// CHECK: ret float [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn float %{{.*}}, f0x42652EE1 +// CHECK: ret float [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x int lowering for degrees is deprecated. Explicitly cast parameters to float types.}} float test_degrees_int(int p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <2 x float> @_Z17test_degrees_int2Dv2_i( +// CHECK-LABEL: test_degrees_int2 // CHECK: [[CONVI:%.*]] = sitofp {{.*}} <2 x i32> %{{.*}} to <2 x float> -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} <2 x float> @llvm.[[TARGET]].degrees.v2f32(<2 x float> [[CONVI]]) -// CHECK: ret <2 x float> [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK: ret <2 x float> [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x int lowering for degrees is deprecated. Explicitly cast parameters to float types.}} float2 test_degrees_int2(int2 p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <3 x float> @_Z17test_degrees_int3Dv3_i( +// CHECK-LABEL: test_degrees_int3 // CHECK: [[CONVI:%.*]] = sitofp {{.*}} <3 x i32> %{{.*}} to <3 x float> -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} <3 x float> @llvm.[[TARGET]].degrees.v3f32(<3 x float> [[CONVI]]) -// CHECK: ret <3 x float> [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK: ret <3 x float> [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x int lowering for degrees is deprecated. Explicitly cast parameters to float types.}} float3 test_degrees_int3(int3 p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <4 x float> @_Z17test_degrees_int4Dv4_i( +// CHECK-LABEL: test_degrees_int4 // CHECK: [[CONVI:%.*]] = sitofp {{.*}} <4 x i32> %{{.*}} to <4 x float> -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} <4 x float> @llvm.[[TARGET]].degrees.v4f32(<4 x float> [[CONVI]]) -// CHECK: ret <4 x float> [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK: ret <4 x float> [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x int lowering for degrees is deprecated. Explicitly cast parameters to float types.}} float4 test_degrees_int4(int4 p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] float @_Z17test_degrees_uintj( +// CHECK-LABEL: test_degrees_uint // CHECK: [[CONVI:%.*]] = uitofp {{.*}} i32 %{{.*}} to float -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} float @llvm.[[TARGET]].degrees.f32(float [[CONVI]]) -// CHECK: ret float [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn float %{{.*}}, f0x42652EE1 +// CHECK: ret float [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x int lowering for degrees is deprecated. Explicitly cast parameters to float types.}} float test_degrees_uint(uint p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <2 x float> @_Z18test_degrees_uint2Dv2_j( +// CHECK-LABEL: test_degrees_uint2 // CHECK: [[CONVI:%.*]] = uitofp {{.*}} <2 x i32> %{{.*}} to <2 x float> -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} <2 x float> @llvm.[[TARGET]].degrees.v2f32(<2 x float> [[CONVI]]) -// CHECK: ret <2 x float> [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK: ret <2 x float> [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x int lowering for degrees is deprecated. Explicitly cast parameters to float types.}} float2 test_degrees_uint2(uint2 p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <3 x float> @_Z18test_degrees_uint3Dv3_j( +// CHECK-LABEL: test_degrees_uint3 // CHECK: [[CONVI:%.*]] = uitofp {{.*}} <3 x i32> %{{.*}} to <3 x float> -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} <3 x float> @llvm.[[TARGET]].degrees.v3f32(<3 x float> [[CONVI]]) -// CHECK: ret <3 x float> [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK: ret <3 x float> [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x int lowering for degrees is deprecated. Explicitly cast parameters to float types.}} float3 test_degrees_uint3(uint3 p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <4 x float> @_Z18test_degrees_uint4Dv4_j( +// CHECK-LABEL: test_degrees_uint4 // CHECK: [[CONVI:%.*]] = uitofp {{.*}} <4 x i32> %{{.*}} to <4 x float> -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} <4 x float> @llvm.[[TARGET]].degrees.v4f32(<4 x float> [[CONVI]]) -// CHECK: ret <4 x float> [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK: ret <4 x float> [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x int lowering for degrees is deprecated. Explicitly cast parameters to float types.}} float4 test_degrees_uint4(uint4 p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] float @_Z20test_degrees_int64_tl( +// CHECK-LABEL: test_degrees_int64_t // CHECK: [[CONVI:%.*]] = sitofp {{.*}} i64 %{{.*}} to float -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} float @llvm.[[TARGET]].degrees.f32(float [[CONVI]]) -// CHECK: ret float [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn float %{{.*}}, f0x42652EE1 +// CHECK: ret float [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x int lowering for degrees is deprecated. Explicitly cast parameters to float types.}} float test_degrees_int64_t(int64_t p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <2 x float> @_Z21test_degrees_int64_t2Dv2_l( +// CHECK-LABEL: test_degrees_int64_t2 // CHECK: [[CONVI:%.*]] = sitofp {{.*}} <2 x i64> %{{.*}} to <2 x float> -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} <2 x float> @llvm.[[TARGET]].degrees.v2f32(<2 x float> [[CONVI]]) -// CHECK: ret <2 x float> [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK: ret <2 x float> [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x int lowering for degrees is deprecated. Explicitly cast parameters to float types.}} float2 test_degrees_int64_t2(int64_t2 p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <3 x float> @_Z21test_degrees_int64_t3Dv3_l( +// CHECK-LABEL: test_degrees_int64_t3 // CHECK: [[CONVI:%.*]] = sitofp {{.*}} <3 x i64> %{{.*}} to <3 x float> -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} <3 x float> @llvm.[[TARGET]].degrees.v3f32(<3 x float> [[CONVI]]) -// CHECK: ret <3 x float> [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK: ret <3 x float> [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x int lowering for degrees is deprecated. Explicitly cast parameters to float types.}} float3 test_degrees_int64_t3(int64_t3 p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <4 x float> @_Z21test_degrees_int64_t4Dv4_l( +// CHECK-LABEL: test_degrees_int64_t4 // CHECK: [[CONVI:%.*]] = sitofp {{.*}} <4 x i64> %{{.*}} to <4 x float> -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} <4 x float> @llvm.[[TARGET]].degrees.v4f32(<4 x float> [[CONVI]]) -// CHECK: ret <4 x float> [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK: ret <4 x float> [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x int lowering for degrees is deprecated. Explicitly cast parameters to float types.}} float4 test_degrees_int64_t4(int64_t4 p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] float @_Z21test_degrees_uint64_tm( +// CHECK-LABEL: test_degrees_uint64_t // CHECK: [[CONVI:%.*]] = uitofp {{.*}} i64 %{{.*}} to float -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} float @llvm.[[TARGET]].degrees.f32(float [[CONVI]]) -// CHECK: ret float [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn float %{{.*}}, f0x42652EE1 +// CHECK: ret float [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x int lowering for degrees is deprecated. Explicitly cast parameters to float types.}} float test_degrees_uint64_t(uint64_t p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <2 x float> @_Z22test_degrees_uint64_t2Dv2_m( +// CHECK-LABEL: test_degrees_uint64_t2 // CHECK: [[CONVI:%.*]] = uitofp {{.*}} <2 x i64> %{{.*}} to <2 x float> -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} <2 x float> @llvm.[[TARGET]].degrees.v2f32(<2 x float> [[CONVI]]) -// CHECK: ret <2 x float> [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK: ret <2 x float> [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x int lowering for degrees is deprecated. Explicitly cast parameters to float types.}} float2 test_degrees_uint64_t2(uint64_t2 p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <3 x float> @_Z22test_degrees_uint64_t3Dv3_m( +// CHECK-LABEL: test_degrees_uint64_t3 // CHECK: [[CONVI:%.*]] = uitofp {{.*}} <3 x i64> %{{.*}} to <3 x float> -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} <3 x float> @llvm.[[TARGET]].degrees.v3f32(<3 x float> [[CONVI]]) -// CHECK: ret <3 x float> [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK: ret <3 x float> [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x int lowering for degrees is deprecated. Explicitly cast parameters to float types.}} float3 test_degrees_uint64_t3(uint64_t3 p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <4 x float> @_Z22test_degrees_uint64_t4Dv4_m( +// CHECK-LABEL: test_degrees_uint64_t4 // CHECK: [[CONVI:%.*]] = uitofp {{.*}} <4 x i64> %{{.*}} to <4 x float> -// CHECK: [[HLSLDEGREESI:%.*]] = call {{.*}} <4 x float> @llvm.[[TARGET]].degrees.v4f32(<4 x float> [[CONVI]]) -// CHECK: ret <4 x float> [[HLSLDEGREESI]] +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK: ret <4 x float> [[MUL]] // expected-warning@+1 {{'degrees' is deprecated: In 202x int lowering for degrees is deprecated. Explicitly cast parameters to float types.}} float4 test_degrees_uint64_t4(uint64_t4 p0) { return degrees(p0); } diff --git a/clang/test/CodeGenHLSL/builtins/degrees.hlsl b/clang/test/CodeGenHLSL/builtins/degrees.hlsl index d403428defbe8..d96bacc54b404 100644 --- a/clang/test/CodeGenHLSL/builtins/degrees.hlsl +++ b/clang/test/CodeGenHLSL/builtins/degrees.hlsl @@ -1,64 +1,37 @@ // RUN: %clang_cc1 -finclude-default-header -triple \ // RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type -fnative-int16-type \ -// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ -// RUN: --check-prefixes=CHECK,NATIVE_HALF \ -// RUN: -DFNATTRS="hidden noundef nofpclass(nan inf)" -DTARGET=dx -// RUN: %clang_cc1 -finclude-default-header -triple \ -// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \ -// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF \ -// RUN: -DFNATTRS="hidden noundef nofpclass(nan inf)" -DTARGET=dx -// RUN: %clang_cc1 -finclude-default-header -triple \ -// RUN: spirv-unknown-vulkan-library %s -fnative-half-type -fnative-int16-type \ -// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ -// RUN: --check-prefixes=CHECK,NATIVE_HALF \ -// RUN: -DFNATTRS="hidden spir_func noundef nofpclass(nan inf)" -DTARGET=spv -// RUN: %clang_cc1 -finclude-default-header -triple \ -// RUN: spirv-unknown-vulkan-library %s -emit-llvm -disable-llvm-passes \ -// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF \ -// RUN: -DFNATTRS="hidden spir_func noundef nofpclass(nan inf)" -DTARGET=spv +// RUN: -emit-llvm -O1 -o - | FileCheck %s -// NATIVE_HALF: define [[FNATTRS]] half @ -// NATIVE_HALF: %hlsl.degrees = call reassoc nnan ninf nsz arcp afn half @llvm.[[TARGET]].degrees.f16( -// NATIVE_HALF: ret half %hlsl.degrees -// NO_HALF: define [[FNATTRS]] float @ -// NO_HALF: %hlsl.degrees = call reassoc nnan ninf nsz arcp afn float @llvm.[[TARGET]].degrees.f32( -// NO_HALF: ret float %hlsl.degrees +// CHECK-LABEL: test_degrees_half +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn half %{{.*}}, 5.728130e+01 +// CHECK-NEXT: ret half [[MUL]] half test_degrees_half(half p0) { return degrees(p0); } -// NATIVE_HALF: define [[FNATTRS]] <2 x half> @ -// NATIVE_HALF: %hlsl.degrees = call reassoc nnan ninf nsz arcp afn <2 x half> @llvm.[[TARGET]].degrees.v2f16 -// NATIVE_HALF: ret <2 x half> %hlsl.degrees -// NO_HALF: define [[FNATTRS]] <2 x float> @ -// NO_HALF: %hlsl.degrees = call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.[[TARGET]].degrees.v2f32( -// NO_HALF: ret <2 x float> %hlsl.degrees +// CHECK-LABEL: test_degrees_half2 +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x half> %{{.*}}, splat (half 5.728130e+01) +// CHECK-NEXT: ret <2 x half> [[MUL]] half2 test_degrees_half2(half2 p0) { return degrees(p0); } -// NATIVE_HALF: define [[FNATTRS]] <3 x half> @ -// NATIVE_HALF: %hlsl.degrees = call reassoc nnan ninf nsz arcp afn <3 x half> @llvm.[[TARGET]].degrees.v3f16 -// NATIVE_HALF: ret <3 x half> %hlsl.degrees -// NO_HALF: define [[FNATTRS]] <3 x float> @ -// NO_HALF: %hlsl.degrees = call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.[[TARGET]].degrees.v3f32( -// NO_HALF: ret <3 x float> %hlsl.degrees +// CHECK-LABEL: test_degrees_half3 +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x half> %{{.*}}, splat (half 5.728130e+01) +// CHECK-NEXT: ret <3 x half> [[MUL]] half3 test_degrees_half3(half3 p0) { return degrees(p0); } -// NATIVE_HALF: define [[FNATTRS]] <4 x half> @ -// NATIVE_HALF: %hlsl.degrees = call reassoc nnan ninf nsz arcp afn <4 x half> @llvm.[[TARGET]].degrees.v4f16 -// NATIVE_HALF: ret <4 x half> %hlsl.degrees -// NO_HALF: define [[FNATTRS]] <4 x float> @ -// NO_HALF: %hlsl.degrees = call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.[[TARGET]].degrees.v4f32( -// NO_HALF: ret <4 x float> %hlsl.degrees +// CHECK-LABEL: test_degrees_half4 +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <4 x half> %{{.*}}, splat (half 5.728130e+01) +// CHECK-NEXT: ret <4 x half> [[MUL]] half4 test_degrees_half4(half4 p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] float @ -// CHECK: %hlsl.degrees = call reassoc nnan ninf nsz arcp afn float @llvm.[[TARGET]].degrees.f32( -// CHECK: ret float %hlsl.degrees +// CHECK-LABEL: test_degrees_float +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn float %{{.*}}, f0x42652EE1 +// CHECK-NEXT: ret float [[MUL]] float test_degrees_float(float p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <2 x float> @ -// CHECK: %hlsl.degrees = call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.[[TARGET]].degrees.v2f32 -// CHECK: ret <2 x float> %hlsl.degrees +// CHECK-LABEL: test_degrees_float2 +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK-NEXT: ret <2 x float> [[MUL]] float2 test_degrees_float2(float2 p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <3 x float> @ -// CHECK: %hlsl.degrees = call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.[[TARGET]].degrees.v3f32 -// CHECK: ret <3 x float> %hlsl.degrees +// CHECK-LABEL: test_degrees_float3 +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK-NEXT: ret <3 x float> [[MUL]] float3 test_degrees_float3(float3 p0) { return degrees(p0); } -// CHECK: define [[FNATTRS]] <4 x float> @ -// CHECK: %hlsl.degrees = call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.[[TARGET]].degrees.v4f32 -// CHECK: ret <4 x float> %hlsl.degrees +// CHECK-LABEL: test_degrees_float4 +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, splat (float f0x42652EE1) +// CHECK-NEXT: ret <4 x float> [[MUL]] float4 test_degrees_float4(float4 p0) { return degrees(p0); } diff --git a/clang/test/SemaHLSL/BuiltIns/degrees-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/degrees-errors.hlsl index 637a6eecfb35a..830b222a8baf0 100644 --- a/clang/test/SemaHLSL/BuiltIns/degrees-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/degrees-errors.hlsl @@ -1,26 +1,34 @@ // RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify float test_too_few_arg() { - return __builtin_hlsl_elementwise_degrees(); - // expected-error@-1 {{too few arguments to function call, expected 1, have 0}} + return degrees(); + // expected-error@-1 {{no matching function for call to 'degrees'}} + // expected-note@hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires single argument 'x', but no arguments were provided}} + // expected-note@hlsl/hlsl_compat_overloads.h:* 20 {{candidate function not viable: requires single argument 'V', but no arguments were provided}} } float2 test_too_many_arg(float2 p0) { - return __builtin_hlsl_elementwise_degrees(p0, p0); - // expected-error@-1 {{too many arguments to function call, expected 1, have 2}} + return degrees(p0, p0); + // expected-error@-1 {{no matching function for call to 'degrees'}} + // expected-note@hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires single argument 'x', but 2 arguments were provided}} + // expected-note@hlsl/hlsl_compat_overloads.h:* 20 {{candidate function not viable: requires single argument 'V', but 2 arguments were provided}} } -float builtin_bool_to_float_type_promotion(bool p1) { - return __builtin_hlsl_elementwise_degrees(p1); - // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'bool')}} +float test_bool_to_float_type_promotion(bool p1) { + return degrees(p1); + // expected-error@-1 {{call to 'degrees' is ambiguous}} + // expected-note@hlsl/hlsl_compat_overloads.h:* 3 {{candidate function}} } -float builtin_degrees_int_to_float_promotion(int p1) { - return __builtin_hlsl_elementwise_degrees(p1); - // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int')}} +float1 test_vec1_inputs(float1 p0) { + return degrees(p0); + // expected-warning@-1 {{implicit conversion turns vector to scalar: 'float1' (aka 'vector<float, 1>') to 'float'}} } -float2 builtin_degrees_int2_to_float2_promotion(int2 p1) { - return __builtin_hlsl_elementwise_degrees(p1); - // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int2' (aka 'vector<int, 2>'))}} +typedef float float5 __attribute__((ext_vector_type(5))); + +float5 test_vec5_inputs(float5 p0) { + return degrees(p0); + // expected-error@-1 {{call to 'degrees' is ambiguous}} + // expected-note@hlsl/hlsl_inline_intrinsics_gen.inc:* 4 {{candidate function}} } diff --git a/clang/test/SemaHLSL/BuiltIns/half-float-only-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/half-float-only-errors.hlsl index e9cc0ed338e3e..5eb97ee870433 100644 --- a/clang/test/SemaHLSL/BuiltIns/half-float-only-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/half-float-only-errors.hlsl @@ -18,7 +18,6 @@ // RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -fnative-int16-type -emit-llvm-only -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_tan // RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -fnative-int16-type -emit-llvm-only -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_tanh // RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -fnative-int16-type -emit-llvm-only -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_trunc -// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -fnative-int16-type -emit-llvm-only -disable-llvm-passes -verify -DTEST_FUNC=__builtin_hlsl_elementwise_degrees // RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -fnative-int16-type -emit-llvm-only -disable-llvm-passes -verify -DTEST_FUNC=__builtin_hlsl_elementwise_radians double test_double_builtin(double p0) { diff --git a/llvm/include/llvm/IR/IntrinsicsDirectX.td b/llvm/include/llvm/IR/IntrinsicsDirectX.td index 0cf68a173930a..ac1dbef9617ab 100644 --- a/llvm/include/llvm/IR/IntrinsicsDirectX.td +++ b/llvm/include/llvm/IR/IntrinsicsDirectX.td @@ -237,7 +237,6 @@ def int_dx_dot4add_i8packed : DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, def int_dx_dot4add_u8packed : DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>; def int_dx_frac : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrTriviallyScalarizable]>; -def int_dx_degrees : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty], [IntrNoMem]>; def int_dx_isinf : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>], [llvm_anyfloat_ty], [IntrNoMem, IntrTriviallyScalarizable]>; diff --git a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp index cbaf21f279581..11e05d804143b 100644 --- a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp +++ b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp @@ -216,7 +216,6 @@ static bool isIntrinsicExpansion(Function &F) { case Intrinsic::dx_uclamp: case Intrinsic::dx_sclamp: case Intrinsic::dx_nclamp: - case Intrinsic::dx_degrees: case Intrinsic::dx_isinf: case Intrinsic::dx_isnan: case Intrinsic::dx_lerp: @@ -1050,14 +1049,6 @@ static Value *expandClampIntrinsic(CallInst *Orig, {MaxCall, Max}, nullptr, "dx.min"); } -static Value *expandDegreesIntrinsic(CallInst *Orig) { - Value *X = Orig->getOperand(0); - Type *Ty = X->getType(); - IRBuilder<> Builder(Orig); - Value *DegreesRatio = ConstantFP::get(Ty, 180.0 * llvm::numbers::inv_pi); - return Builder.CreateFMul(X, DegreesRatio); -} - static Value *expandSignIntrinsic(CallInst *Orig) { Value *X = Orig->getOperand(0); Type *Ty = X->getType(); @@ -1313,9 +1304,6 @@ static bool expandIntrinsic(Function &F, CallInst *Orig) { case Intrinsic::dx_nclamp: Result = expandClampIntrinsic(Orig, IntrinsicId); break; - case Intrinsic::dx_degrees: - Result = expandDegreesIntrinsic(Orig); - break; case Intrinsic::dx_isinf: Result = expand16BitIsInf(Orig); break; diff --git a/llvm/test/CodeGen/DirectX/degrees.ll b/llvm/test/CodeGen/DirectX/degrees.ll deleted file mode 100644 index ebb5511afcc54..0000000000000 --- a/llvm/test/CodeGen/DirectX/degrees.ll +++ /dev/null @@ -1,54 +0,0 @@ -; RUN: opt -S -dxil-intrinsic-expansion -scalarizer -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s - -; Make sure dxil op function calls for degrees are expanded and lowered as fmul for float and half. - -define noundef half @degrees_half(half noundef %a) { -; CHECK-LABEL: define noundef half @degrees_half( -; CHECK-SAME: half noundef [[A:%.*]]) { -; CHECK-NEXT: [[ENTRY:.*:]] -; CHECK-NEXT: [[DX_DEGREES1:%.*]] = fmul half [[A]], 5.728130e+01 -; CHECK-NEXT: ret half [[DX_DEGREES1]] -; -entry: - %dx.degrees = call half @llvm.dx.degrees.f16(half %a) - ret half %dx.degrees -} - -define noundef float @degrees_float(float noundef %a) #0 { -; CHECK-LABEL: define noundef float @degrees_float( -; CHECK-SAME: float noundef [[A:%.*]]) { -; CHECK-NEXT: entry: -; CHECK-NEXT: [[DEGREES:%.*]] = fmul float [[A]], f0x42652EE1 -; CHECK-NEXT: ret float [[DEGREES]] -; -entry: - %dx.degrees = call float @llvm.dx.degrees.f32(float %a) - ret float %dx.degrees -} - -define noundef <4 x float> @degrees_float4(<4 x float> noundef %a) #0 { -; CHECK-LABEL: define noundef <4 x float> @degrees_float4( -; CHECK-SAME: <4 x float> noundef [[A:%.*]]) { -; CHECK-NEXT: entry: -; CHECK-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A]], i64 0 -; CHECK-NEXT: [[DEGREES_A0:%.*]] = fmul float [[A0]], f0x42652EE1 -; CHECK-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i64 1 -; CHECK-NEXT: [[DEGREES_A1:%.*]] = fmul float [[A1]], f0x42652EE1 -; CHECK-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i64 2 -; CHECK-NEXT: [[DEGREES_A2:%.*]] = fmul float [[A2]], f0x42652EE1 -; CHECK-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i64 3 -; CHECK-NEXT: [[DEGREES_A3:%.*]] = fmul float [[A3]], f0x42652EE1 -; CHECK-NEXT: [[INSERT_0:%.*]] = insertelement <4 x float> poison, float [[DEGREES_A0]], i64 0 -; CHECK-NEXT: [[INSERT_1:%.*]] = insertelement <4 x float> [[INSERT_0]], float [[DEGREES_A1]], i64 1 -; CHECK-NEXT: [[INSERT_2:%.*]] = insertelement <4 x float> [[INSERT_1]], float [[DEGREES_A2]], i64 2 -; CHECK-NEXT: [[RES:%.*]] = insertelement <4 x float> [[INSERT_2]], float [[DEGREES_A3]], i64 3 -; CHECK-NEXT: ret <4 x float> [[RES]] -; -entry: - %2 = call <4 x float> @llvm.dx.degrees.v4f32(<4 x float> %a) - ret <4 x float> %2 -} - -declare half @llvm.dx.degrees.f16(half) -declare float @llvm.dx.degrees.f32(float) -declare <4 x float> @llvm.dx.degrees.v4f32(<4 x float>) >From fd06b96484eab979525640774a72db216b7bf615 Mon Sep 17 00:00:00 2001 From: kmpeng <[email protected]> Date: Tue, 11 Aug 2026 17:34:34 -0700 Subject: [PATCH 2/2] update based on `radians` PR comments --- clang/lib/Headers/hlsl/hlsl_detail.h | 2 +- .../lib/Headers/hlsl/hlsl_intrinsic_helpers.h | 2 +- .../builtins/degrees-overloads.hlsl | 2 ++ clang/test/CodeGenHLSL/builtins/degrees.hlsl | 2 ++ .../SemaHLSL/BuiltIns/degrees-errors.hlsl | 34 ------------------- 5 files changed, 6 insertions(+), 36 deletions(-) delete mode 100644 clang/test/SemaHLSL/BuiltIns/degrees-errors.hlsl diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h b/clang/lib/Headers/hlsl/hlsl_detail.h index cf8655ae19705..8ce925bb8fbe4 100644 --- a/clang/lib/Headers/hlsl/hlsl_detail.h +++ b/clang/lib/Headers/hlsl/hlsl_detail.h @@ -13,7 +13,7 @@ namespace hlsl { namespace __detail { -constexpr double pi = 3.141592653589793L; +constexpr double Pi = 3.14159265358979323846L; template <typename T, typename U> struct is_same { static const bool value = false; diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h index 8b6742ddeec7f..85ac8f1a1b901 100644 --- a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h @@ -177,7 +177,7 @@ template <typename T> constexpr T fwidth_impl(T input) { } template <typename T> constexpr T degrees_impl(T Val) { - return Val * (T)(180 / pi); + return Val * (T)(180.L / Pi); } } // namespace __detail diff --git a/clang/test/CodeGenHLSL/builtins/degrees-overloads.hlsl b/clang/test/CodeGenHLSL/builtins/degrees-overloads.hlsl index e49bd354a97fa..c514128c790be 100644 --- a/clang/test/CodeGenHLSL/builtins/degrees-overloads.hlsl +++ b/clang/test/CodeGenHLSL/builtins/degrees-overloads.hlsl @@ -4,6 +4,8 @@ // RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s \ // RUN: -verify -verify-ignore-unexpected=note +// Note: the f0x42652EE1 constants below equal 180/Pi. + // CHECK-LABEL: test_degrees_double // CHECK: [[CONVI:%.*]] = fptrunc {{.*}} double %{{.*}} to float // CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn float %{{.*}}, f0x42652EE1 diff --git a/clang/test/CodeGenHLSL/builtins/degrees.hlsl b/clang/test/CodeGenHLSL/builtins/degrees.hlsl index d96bacc54b404..2be034b8c90de 100644 --- a/clang/test/CodeGenHLSL/builtins/degrees.hlsl +++ b/clang/test/CodeGenHLSL/builtins/degrees.hlsl @@ -2,6 +2,8 @@ // RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type -fnative-int16-type \ // RUN: -emit-llvm -O1 -o - | FileCheck %s +// Note: the 5.728130e+01 and f0x42652EE1 constants below equal 180/Pi. + // CHECK-LABEL: test_degrees_half // CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn half %{{.*}}, 5.728130e+01 // CHECK-NEXT: ret half [[MUL]] diff --git a/clang/test/SemaHLSL/BuiltIns/degrees-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/degrees-errors.hlsl deleted file mode 100644 index 830b222a8baf0..0000000000000 --- a/clang/test/SemaHLSL/BuiltIns/degrees-errors.hlsl +++ /dev/null @@ -1,34 +0,0 @@ -// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify - -float test_too_few_arg() { - return degrees(); - // expected-error@-1 {{no matching function for call to 'degrees'}} - // expected-note@hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires single argument 'x', but no arguments were provided}} - // expected-note@hlsl/hlsl_compat_overloads.h:* 20 {{candidate function not viable: requires single argument 'V', but no arguments were provided}} -} - -float2 test_too_many_arg(float2 p0) { - return degrees(p0, p0); - // expected-error@-1 {{no matching function for call to 'degrees'}} - // expected-note@hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires single argument 'x', but 2 arguments were provided}} - // expected-note@hlsl/hlsl_compat_overloads.h:* 20 {{candidate function not viable: requires single argument 'V', but 2 arguments were provided}} -} - -float test_bool_to_float_type_promotion(bool p1) { - return degrees(p1); - // expected-error@-1 {{call to 'degrees' is ambiguous}} - // expected-note@hlsl/hlsl_compat_overloads.h:* 3 {{candidate function}} -} - -float1 test_vec1_inputs(float1 p0) { - return degrees(p0); - // expected-warning@-1 {{implicit conversion turns vector to scalar: 'float1' (aka 'vector<float, 1>') to 'float'}} -} - -typedef float float5 __attribute__((ext_vector_type(5))); - -float5 test_vec5_inputs(float5 p0) { - return degrees(p0); - // expected-error@-1 {{call to 'degrees' is ambiguous}} - // expected-note@hlsl/hlsl_inline_intrinsics_gen.inc:* 4 {{candidate function}} -} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
