Author: Kaitlin Peng Date: 2026-08-12T18:47:21Z New Revision: 328382a99c5f206c1d92516f5cb096fbfab99631
URL: https://github.com/llvm/llvm-project/commit/328382a99c5f206c1d92516f5cb096fbfab99631 DIFF: https://github.com/llvm/llvm-project/commit/328382a99c5f206c1d92516f5cb096fbfab99631.diff LOG: [HLSL] Move `degrees` implementation to header files (#215436) Closes #213096. This PR replaces the previous implementation of `degrees` with a new one inside the header files. The SPIRV intrinsic (`int_spv_degrees`) and its lowering are intentionally kept, since a follow-up will pattern-match `Val * (180/pi)` back to the extended instruction and needs the SPIRV intrinsic to do so. Assisted-by: Claude Opus 4.8 Added: Modified: clang/include/clang/Basic/Builtins.td clang/include/clang/Basic/HLSLIntrinsics.td clang/lib/CodeGen/CGHLSLBuiltins.cpp clang/lib/CodeGen/CGHLSLRuntime.h clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h clang/lib/Sema/SemaHLSL.cpp clang/test/CodeGenHLSL/builtins/degrees-overloads.hlsl clang/test/CodeGenHLSL/builtins/degrees.hlsl clang/test/SemaHLSL/BuiltIns/half-float-only-errors.hlsl llvm/include/llvm/IR/IntrinsicsDirectX.td llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp Removed: clang/test/CodeGenHLSL/builtins/degrees-builtin.hlsl clang/test/SemaHLSL/BuiltIns/degrees-errors.hlsl llvm/test/CodeGen/DirectX/degrees.ll ################################################################################ diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index a06c03b8e915f..88aa8aee01e4b 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 972efd2fb90af..fa5cb896e795a 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 93cddd2149153..83c0bb2ac684b 100644 --- a/clang/lib/CodeGen/CGHLSLBuiltins.cpp +++ b/clang/lib/CodeGen/CGHLSLBuiltins.cpp @@ -1148,16 +1148,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 31f4473bd2303..0b282f19cfcbc 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_intrinsic_helpers.h b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h index 1d0c3fa80a255..977059a9fdae0 100644 --- a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h @@ -180,6 +180,10 @@ template <typename T> constexpr T fwidth_impl(T input) { #endif } +template <typename T> constexpr T degrees_impl(T Val) { + return Val * (T)(180.L / Pi); +} + template <typename T> constexpr T radians_impl(T Val) { return Val * (T)(Pi / 180.L); } diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 854063e6ba8ce..184339044e5bf 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -4437,7 +4437,6 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { return true; break; } - case Builtin::BI__builtin_hlsl_elementwise_degrees: case Builtin::BI__builtin_hlsl_elementwise_rsqrt: case Builtin::BI__builtin_hlsl_elementwise_frac: case Builtin::BI__builtin_hlsl_elementwise_ddx_coarse: 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..c514128c790be 100644 --- a/clang/test/CodeGenHLSL/builtins/degrees-overloads.hlsl +++ b/clang/test/CodeGenHLSL/builtins/degrees-overloads.hlsl @@ -1,137 +1,132 @@ // 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( +// Note: the f0x42652EE1 constants below equal 180/Pi. + +// 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..2be034b8c90de 100644 --- a/clang/test/CodeGenHLSL/builtins/degrees.hlsl +++ b/clang/test/CodeGenHLSL/builtins/degrees.hlsl @@ -1,64 +1,39 @@ // 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 + +// Note: the 5.728130e+01 and f0x42652EE1 constants below equal 180/Pi. -// 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 deleted file mode 100644 index 637a6eecfb35a..0000000000000 --- a/clang/test/SemaHLSL/BuiltIns/degrees-errors.hlsl +++ /dev/null @@ -1,26 +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 __builtin_hlsl_elementwise_degrees(); - // expected-error@-1 {{too few arguments to function call, expected 1, have 0}} -} - -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}} -} - -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 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')}} -} - -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>'))}} -} diff --git a/clang/test/SemaHLSL/BuiltIns/half-float-only-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/half-float-only-errors.hlsl index ce6434280796f..fcf0711bf6965 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 double test_double_builtin(double p0) { return TEST_FUNC(p0); diff --git a/llvm/include/llvm/IR/IntrinsicsDirectX.td b/llvm/include/llvm/IR/IntrinsicsDirectX.td index c6fecc266c317..033de14304fe6 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 81c2925c73fa6..8ecc7ddc4b64f 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_normalize: @@ -1030,14 +1029,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(); @@ -1289,9 +1280,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>) _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
