[clang] [HLSL] Add matrix support for degrees(), radians() (PR #218573)
Dan Brown via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 26 14:56:04 PDT 2026
https://github.com/danbrown-amd updated https://github.com/llvm/llvm-project/pull/218573
>From 35ab52902e105f2aca5b1be5d7a082fae9c8d8ea Mon Sep 17 00:00:00 2001
From: danbrown-amd <danbrown at amd.com>
Date: Fri, 21 Aug 2026 18:19:51 -0600
Subject: [PATCH 1/3] [HLSL] Add matrix support for degrees(), radians()
Resolves #184480, #184485
Assisted-by: Claude Opus 4
---
clang/include/clang/Basic/HLSLIntrinsics.td | 2 -
clang/lib/Headers/hlsl/hlsl_detail.h | 11 +
.../lib/Headers/hlsl/hlsl_intrinsic_helpers.h | 4 +-
.../CodeGenHLSL/builtins/degrees_mat.hlsl | 195 ++++++++++++++++++
.../CodeGenHLSL/builtins/radians_mat.hlsl | 195 ++++++++++++++++++
5 files changed, 403 insertions(+), 4 deletions(-)
create mode 100644 clang/test/CodeGenHLSL/builtins/degrees_mat.hlsl
create mode 100644 clang/test/CodeGenHLSL/builtins/radians_mat.hlsl
diff --git a/clang/include/clang/Basic/HLSLIntrinsics.td b/clang/include/clang/Basic/HLSLIntrinsics.td
index 42887bbc3b811..ba2ced302631e 100644
--- a/clang/include/clang/Basic/HLSLIntrinsics.td
+++ b/clang/include/clang/Basic/HLSLIntrinsics.td
@@ -702,7 +702,6 @@ def hlsl_degrees : HLSLOneArgDetail<"degrees", "degrees_impl"> {
}];
let ParamNames = ["x"];
let VaryingTypes = [HalfTy, FloatTy];
- let VaryingMatDims = [];
}
// Returns the cross product of two floating-point, 3D vectors.
def hlsl_cross : HLSLTwoArgDetail<"cross", "cross_impl"> {
@@ -1399,7 +1398,6 @@ def hlsl_radians : HLSLOneArgDetail<"radians", "radians_impl"> {
}];
let ParamNames = ["Val"];
let VaryingTypes = [HalfTy, FloatTy];
- let VaryingMatDims = [];
}
// Calculates a fast, approximate, per-component reciprocal ie 1 / x.
diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h b/clang/lib/Headers/hlsl/hlsl_detail.h
index 8ce925bb8fbe4..bc9d23af95c17 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -53,6 +53,17 @@ template <typename T> struct is_arithmetic {
static const bool Value = __is_arithmetic(T);
};
+template <typename T> struct elem_type {
+ using Type = T;
+};
+template <typename T, int N> struct elem_type<vector<T, N>> {
+ using Type = T;
+};
+template <typename T, int R, int C> struct elem_type<matrix<T, R, C>> {
+ using Type = T;
+};
+template <typename T> using elem_type_t = typename elem_type<T>::Type;
+
} // namespace __detail
} // namespace hlsl
#endif //_HLSL_HLSL_DETAILS_H_
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
index 977059a9fdae0..9bf3e0298cf09 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
@@ -181,11 +181,11 @@ template <typename T> constexpr T fwidth_impl(T input) {
}
template <typename T> constexpr T degrees_impl(T Val) {
- return Val * (T)(180.L / Pi);
+ return Val * (elem_type_t<T>)(180.L / Pi);
}
template <typename T> constexpr T radians_impl(T Val) {
- return Val * (T)(Pi / 180.L);
+ return Val * (elem_type_t<T>)(Pi / 180.L);
}
} // namespace __detail
diff --git a/clang/test/CodeGenHLSL/builtins/degrees_mat.hlsl b/clang/test/CodeGenHLSL/builtins/degrees_mat.hlsl
new file mode 100644
index 0000000000000..97b6aff3ba55d
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/degrees_mat.hlsl
@@ -0,0 +1,195 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN: dxil-pc-shadermodel6.3-library %s \
+// RUN: -fnative-half-type -fnative-int16-type -emit-llvm -o - \
+// RUN: | FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -o - \
+// RUN: | FileCheck %s --check-prefixes=CHECK,NO_HALF
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN: spirv-unknown-vulkan-library %s \
+// RUN: -fnative-half-type -fnative-int16-type -emit-llvm -o - \
+// RUN: | FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN: spirv-unknown-vulkan-library %s -emit-llvm -o - \
+// RUN: | FileCheck %s --check-prefixes=CHECK,NO_HALF
+
+// CHECK-LABEL: test_degrees_half1x2
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <2 x half> {{.*}}, splat (half 5.728130e+01)
+// NATIVE_HALF: ret <2 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <2 x float> {{.*}}, splat (float f0x42652EE1)
+// NO_HALF: ret <2 x float>
+half1x2 test_degrees_half1x2(half1x2 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_half1x3
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <3 x half> {{.*}}, splat (half 5.728130e+01)
+// NATIVE_HALF: ret <3 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <3 x float> {{.*}}, splat (float f0x42652EE1)
+// NO_HALF: ret <3 x float>
+half1x3 test_degrees_half1x3(half1x3 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_half1x4
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 5.728130e+01)
+// NATIVE_HALF: ret <4 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x42652EE1)
+// NO_HALF: ret <4 x float>
+half1x4 test_degrees_half1x4(half1x4 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_half2x1
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <2 x half> {{.*}}, splat (half 5.728130e+01)
+// NATIVE_HALF: ret <2 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <2 x float> {{.*}}, splat (float f0x42652EE1)
+// NO_HALF: ret <2 x float>
+half2x1 test_degrees_half2x1(half2x1 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_half2x2
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 5.728130e+01)
+// NATIVE_HALF: ret <4 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x42652EE1)
+// NO_HALF: ret <4 x float>
+half2x2 test_degrees_half2x2(half2x2 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_half2x3
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <6 x half> {{.*}}, splat (half 5.728130e+01)
+// NATIVE_HALF: ret <6 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <6 x float> {{.*}}, splat (float f0x42652EE1)
+// NO_HALF: ret <6 x float>
+half2x3 test_degrees_half2x3(half2x3 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_half2x4
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <8 x half> {{.*}}, splat (half 5.728130e+01)
+// NATIVE_HALF: ret <8 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <8 x float> {{.*}}, splat (float f0x42652EE1)
+// NO_HALF: ret <8 x float>
+half2x4 test_degrees_half2x4(half2x4 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_half3x1
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <3 x half> {{.*}}, splat (half 5.728130e+01)
+// NATIVE_HALF: ret <3 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <3 x float> {{.*}}, splat (float f0x42652EE1)
+// NO_HALF: ret <3 x float>
+half3x1 test_degrees_half3x1(half3x1 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_half3x2
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <6 x half> {{.*}}, splat (half 5.728130e+01)
+// NATIVE_HALF: ret <6 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <6 x float> {{.*}}, splat (float f0x42652EE1)
+// NO_HALF: ret <6 x float>
+half3x2 test_degrees_half3x2(half3x2 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_half3x3
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <9 x half> {{.*}}, splat (half 5.728130e+01)
+// NATIVE_HALF: ret <9 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <9 x float> {{.*}}, splat (float f0x42652EE1)
+// NO_HALF: ret <9 x float>
+half3x3 test_degrees_half3x3(half3x3 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_half3x4
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <12 x half> {{.*}}, splat (half 5.728130e+01)
+// NATIVE_HALF: ret <12 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <12 x float> {{.*}}, splat (float f0x42652EE1)
+// NO_HALF: ret <12 x float>
+half3x4 test_degrees_half3x4(half3x4 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_half4x1
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 5.728130e+01)
+// NATIVE_HALF: ret <4 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x42652EE1)
+// NO_HALF: ret <4 x float>
+half4x1 test_degrees_half4x1(half4x1 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_half4x2
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <8 x half> {{.*}}, splat (half 5.728130e+01)
+// NATIVE_HALF: ret <8 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <8 x float> {{.*}}, splat (float f0x42652EE1)
+// NO_HALF: ret <8 x float>
+half4x2 test_degrees_half4x2(half4x2 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_half4x3
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <12 x half> {{.*}}, splat (half 5.728130e+01)
+// NATIVE_HALF: ret <12 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <12 x float> {{.*}}, splat (float f0x42652EE1)
+// NO_HALF: ret <12 x float>
+half4x3 test_degrees_half4x3(half4x3 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_half4x4
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <16 x half> {{.*}}, splat (half 5.728130e+01)
+// NATIVE_HALF: ret <16 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <16 x float> {{.*}}, splat (float f0x42652EE1)
+// NO_HALF: ret <16 x float>
+half4x4 test_degrees_half4x4(half4x4 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_float1x2
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <2 x float> {{.*}}, splat (float f0x42652EE1)
+// CHECK: ret <2 x float>
+float1x2 test_degrees_float1x2(float1x2 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_float1x3
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <3 x float> {{.*}}, splat (float f0x42652EE1)
+// CHECK: ret <3 x float>
+float1x3 test_degrees_float1x3(float1x3 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_float1x4
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x42652EE1)
+// CHECK: ret <4 x float>
+float1x4 test_degrees_float1x4(float1x4 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_float2x1
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <2 x float> {{.*}}, splat (float f0x42652EE1)
+// CHECK: ret <2 x float>
+float2x1 test_degrees_float2x1(float2x1 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_float2x2
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x42652EE1)
+// CHECK: ret <4 x float>
+float2x2 test_degrees_float2x2(float2x2 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_float2x3
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <6 x float> {{.*}}, splat (float f0x42652EE1)
+// CHECK: ret <6 x float>
+float2x3 test_degrees_float2x3(float2x3 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_float2x4
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <8 x float> {{.*}}, splat (float f0x42652EE1)
+// CHECK: ret <8 x float>
+float2x4 test_degrees_float2x4(float2x4 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_float3x1
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <3 x float> {{.*}}, splat (float f0x42652EE1)
+// CHECK: ret <3 x float>
+float3x1 test_degrees_float3x1(float3x1 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_float3x2
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <6 x float> {{.*}}, splat (float f0x42652EE1)
+// CHECK: ret <6 x float>
+float3x2 test_degrees_float3x2(float3x2 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_float3x3
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <9 x float> {{.*}}, splat (float f0x42652EE1)
+// CHECK: ret <9 x float>
+float3x3 test_degrees_float3x3(float3x3 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_float3x4
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <12 x float> {{.*}}, splat (float f0x42652EE1)
+// CHECK: ret <12 x float>
+float3x4 test_degrees_float3x4(float3x4 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_float4x1
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x42652EE1)
+// CHECK: ret <4 x float>
+float4x1 test_degrees_float4x1(float4x1 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_float4x2
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <8 x float> {{.*}}, splat (float f0x42652EE1)
+// CHECK: ret <8 x float>
+float4x2 test_degrees_float4x2(float4x2 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_float4x3
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <12 x float> {{.*}}, splat (float f0x42652EE1)
+// CHECK: ret <12 x float>
+float4x3 test_degrees_float4x3(float4x3 p0) { return degrees(p0); }
+
+// CHECK-LABEL: test_degrees_float4x4
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <16 x float> {{.*}}, splat (float f0x42652EE1)
+// CHECK: ret <16 x float>
+float4x4 test_degrees_float4x4(float4x4 p0) { return degrees(p0); }
+
diff --git a/clang/test/CodeGenHLSL/builtins/radians_mat.hlsl b/clang/test/CodeGenHLSL/builtins/radians_mat.hlsl
new file mode 100644
index 0000000000000..60f55f20f7326
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/radians_mat.hlsl
@@ -0,0 +1,195 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN: dxil-pc-shadermodel6.3-library %s \
+// RUN: -fnative-half-type -fnative-int16-type -emit-llvm -o - \
+// RUN: | FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -o - \
+// RUN: | FileCheck %s --check-prefixes=CHECK,NO_HALF
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN: spirv-unknown-vulkan-library %s \
+// RUN: -fnative-half-type -fnative-int16-type -emit-llvm -o - \
+// RUN: | FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN: spirv-unknown-vulkan-library %s -emit-llvm -o - \
+// RUN: | FileCheck %s --check-prefixes=CHECK,NO_HALF
+
+// CHECK-LABEL: test_radians_half1x2
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <2 x half> {{.*}}, splat (half 1.745610e-02)
+// NATIVE_HALF: ret <2 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <2 x float> {{.*}}, splat (float f0x3C8EFA35)
+// NO_HALF: ret <2 x float>
+half1x2 test_radians_half1x2(half1x2 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_half1x3
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <3 x half> {{.*}}, splat (half 1.745610e-02)
+// NATIVE_HALF: ret <3 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <3 x float> {{.*}}, splat (float f0x3C8EFA35)
+// NO_HALF: ret <3 x float>
+half1x3 test_radians_half1x3(half1x3 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_half1x4
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 1.745610e-02)
+// NATIVE_HALF: ret <4 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x3C8EFA35)
+// NO_HALF: ret <4 x float>
+half1x4 test_radians_half1x4(half1x4 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_half2x1
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <2 x half> {{.*}}, splat (half 1.745610e-02)
+// NATIVE_HALF: ret <2 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <2 x float> {{.*}}, splat (float f0x3C8EFA35)
+// NO_HALF: ret <2 x float>
+half2x1 test_radians_half2x1(half2x1 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_half2x2
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 1.745610e-02)
+// NATIVE_HALF: ret <4 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x3C8EFA35)
+// NO_HALF: ret <4 x float>
+half2x2 test_radians_half2x2(half2x2 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_half2x3
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <6 x half> {{.*}}, splat (half 1.745610e-02)
+// NATIVE_HALF: ret <6 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <6 x float> {{.*}}, splat (float f0x3C8EFA35)
+// NO_HALF: ret <6 x float>
+half2x3 test_radians_half2x3(half2x3 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_half2x4
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <8 x half> {{.*}}, splat (half 1.745610e-02)
+// NATIVE_HALF: ret <8 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <8 x float> {{.*}}, splat (float f0x3C8EFA35)
+// NO_HALF: ret <8 x float>
+half2x4 test_radians_half2x4(half2x4 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_half3x1
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <3 x half> {{.*}}, splat (half 1.745610e-02)
+// NATIVE_HALF: ret <3 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <3 x float> {{.*}}, splat (float f0x3C8EFA35)
+// NO_HALF: ret <3 x float>
+half3x1 test_radians_half3x1(half3x1 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_half3x2
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <6 x half> {{.*}}, splat (half 1.745610e-02)
+// NATIVE_HALF: ret <6 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <6 x float> {{.*}}, splat (float f0x3C8EFA35)
+// NO_HALF: ret <6 x float>
+half3x2 test_radians_half3x2(half3x2 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_half3x3
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <9 x half> {{.*}}, splat (half 1.745610e-02)
+// NATIVE_HALF: ret <9 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <9 x float> {{.*}}, splat (float f0x3C8EFA35)
+// NO_HALF: ret <9 x float>
+half3x3 test_radians_half3x3(half3x3 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_half3x4
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <12 x half> {{.*}}, splat (half 1.745610e-02)
+// NATIVE_HALF: ret <12 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <12 x float> {{.*}}, splat (float f0x3C8EFA35)
+// NO_HALF: ret <12 x float>
+half3x4 test_radians_half3x4(half3x4 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_half4x1
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 1.745610e-02)
+// NATIVE_HALF: ret <4 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x3C8EFA35)
+// NO_HALF: ret <4 x float>
+half4x1 test_radians_half4x1(half4x1 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_half4x2
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <8 x half> {{.*}}, splat (half 1.745610e-02)
+// NATIVE_HALF: ret <8 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <8 x float> {{.*}}, splat (float f0x3C8EFA35)
+// NO_HALF: ret <8 x float>
+half4x2 test_radians_half4x2(half4x2 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_half4x3
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <12 x half> {{.*}}, splat (half 1.745610e-02)
+// NATIVE_HALF: ret <12 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <12 x float> {{.*}}, splat (float f0x3C8EFA35)
+// NO_HALF: ret <12 x float>
+half4x3 test_radians_half4x3(half4x3 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_half4x4
+// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <16 x half> {{.*}}, splat (half 1.745610e-02)
+// NATIVE_HALF: ret <16 x half>
+// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <16 x float> {{.*}}, splat (float f0x3C8EFA35)
+// NO_HALF: ret <16 x float>
+half4x4 test_radians_half4x4(half4x4 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_float1x2
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <2 x float> {{.*}}, splat (float f0x3C8EFA35)
+// CHECK: ret <2 x float>
+float1x2 test_radians_float1x2(float1x2 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_float1x3
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <3 x float> {{.*}}, splat (float f0x3C8EFA35)
+// CHECK: ret <3 x float>
+float1x3 test_radians_float1x3(float1x3 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_float1x4
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x3C8EFA35)
+// CHECK: ret <4 x float>
+float1x4 test_radians_float1x4(float1x4 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_float2x1
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <2 x float> {{.*}}, splat (float f0x3C8EFA35)
+// CHECK: ret <2 x float>
+float2x1 test_radians_float2x1(float2x1 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_float2x2
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x3C8EFA35)
+// CHECK: ret <4 x float>
+float2x2 test_radians_float2x2(float2x2 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_float2x3
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <6 x float> {{.*}}, splat (float f0x3C8EFA35)
+// CHECK: ret <6 x float>
+float2x3 test_radians_float2x3(float2x3 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_float2x4
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <8 x float> {{.*}}, splat (float f0x3C8EFA35)
+// CHECK: ret <8 x float>
+float2x4 test_radians_float2x4(float2x4 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_float3x1
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <3 x float> {{.*}}, splat (float f0x3C8EFA35)
+// CHECK: ret <3 x float>
+float3x1 test_radians_float3x1(float3x1 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_float3x2
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <6 x float> {{.*}}, splat (float f0x3C8EFA35)
+// CHECK: ret <6 x float>
+float3x2 test_radians_float3x2(float3x2 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_float3x3
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <9 x float> {{.*}}, splat (float f0x3C8EFA35)
+// CHECK: ret <9 x float>
+float3x3 test_radians_float3x3(float3x3 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_float3x4
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <12 x float> {{.*}}, splat (float f0x3C8EFA35)
+// CHECK: ret <12 x float>
+float3x4 test_radians_float3x4(float3x4 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_float4x1
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x3C8EFA35)
+// CHECK: ret <4 x float>
+float4x1 test_radians_float4x1(float4x1 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_float4x2
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <8 x float> {{.*}}, splat (float f0x3C8EFA35)
+// CHECK: ret <8 x float>
+float4x2 test_radians_float4x2(float4x2 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_float4x3
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <12 x float> {{.*}}, splat (float f0x3C8EFA35)
+// CHECK: ret <12 x float>
+float4x3 test_radians_float4x3(float4x3 p0) { return radians(p0); }
+
+// CHECK-LABEL: test_radians_float4x4
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <16 x float> {{.*}}, splat (float f0x3C8EFA35)
+// CHECK: ret <16 x float>
+float4x4 test_radians_float4x4(float4x4 p0) { return radians(p0); }
+
>From a908099a9a6d3d2f38b99eeb6a4f9f5c3ad5c193 Mon Sep 17 00:00:00 2001
From: danbrown-amd <danbrown at amd.com>
Date: Wed, 26 Aug 2026 14:45:53 -0600
Subject: [PATCH 2/3] Eliminate superfluous RUN lines
---
.../CodeGenHLSL/builtins/degrees_mat.hlsl | 102 ++++++------------
.../CodeGenHLSL/builtins/radians_mat.hlsl | 102 ++++++------------
2 files changed, 62 insertions(+), 142 deletions(-)
diff --git a/clang/test/CodeGenHLSL/builtins/degrees_mat.hlsl b/clang/test/CodeGenHLSL/builtins/degrees_mat.hlsl
index 97b6aff3ba55d..f9423237a8c22 100644
--- a/clang/test/CodeGenHLSL/builtins/degrees_mat.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/degrees_mat.hlsl
@@ -1,121 +1,81 @@
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
// RUN: dxil-pc-shadermodel6.3-library %s \
// RUN: -fnative-half-type -fnative-int16-type -emit-llvm -o - \
-// RUN: | FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -o - \
-// RUN: | FileCheck %s --check-prefixes=CHECK,NO_HALF
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN: spirv-unknown-vulkan-library %s \
-// RUN: -fnative-half-type -fnative-int16-type -emit-llvm -o - \
-// RUN: | FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN: spirv-unknown-vulkan-library %s -emit-llvm -o - \
-// RUN: | FileCheck %s --check-prefixes=CHECK,NO_HALF
+// RUN: | FileCheck %s
// CHECK-LABEL: test_degrees_half1x2
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <2 x half> {{.*}}, splat (half 5.728130e+01)
-// NATIVE_HALF: ret <2 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <2 x float> {{.*}}, splat (float f0x42652EE1)
-// NO_HALF: ret <2 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <2 x half> {{.*}}, splat (half 5.728130e+01)
+// CHECK: ret <2 x half>
half1x2 test_degrees_half1x2(half1x2 p0) { return degrees(p0); }
// CHECK-LABEL: test_degrees_half1x3
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <3 x half> {{.*}}, splat (half 5.728130e+01)
-// NATIVE_HALF: ret <3 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <3 x float> {{.*}}, splat (float f0x42652EE1)
-// NO_HALF: ret <3 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <3 x half> {{.*}}, splat (half 5.728130e+01)
+// CHECK: ret <3 x half>
half1x3 test_degrees_half1x3(half1x3 p0) { return degrees(p0); }
// CHECK-LABEL: test_degrees_half1x4
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 5.728130e+01)
-// NATIVE_HALF: ret <4 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x42652EE1)
-// NO_HALF: ret <4 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 5.728130e+01)
+// CHECK: ret <4 x half>
half1x4 test_degrees_half1x4(half1x4 p0) { return degrees(p0); }
// CHECK-LABEL: test_degrees_half2x1
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <2 x half> {{.*}}, splat (half 5.728130e+01)
-// NATIVE_HALF: ret <2 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <2 x float> {{.*}}, splat (float f0x42652EE1)
-// NO_HALF: ret <2 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <2 x half> {{.*}}, splat (half 5.728130e+01)
+// CHECK: ret <2 x half>
half2x1 test_degrees_half2x1(half2x1 p0) { return degrees(p0); }
// CHECK-LABEL: test_degrees_half2x2
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 5.728130e+01)
-// NATIVE_HALF: ret <4 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x42652EE1)
-// NO_HALF: ret <4 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 5.728130e+01)
+// CHECK: ret <4 x half>
half2x2 test_degrees_half2x2(half2x2 p0) { return degrees(p0); }
// CHECK-LABEL: test_degrees_half2x3
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <6 x half> {{.*}}, splat (half 5.728130e+01)
-// NATIVE_HALF: ret <6 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <6 x float> {{.*}}, splat (float f0x42652EE1)
-// NO_HALF: ret <6 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <6 x half> {{.*}}, splat (half 5.728130e+01)
+// CHECK: ret <6 x half>
half2x3 test_degrees_half2x3(half2x3 p0) { return degrees(p0); }
// CHECK-LABEL: test_degrees_half2x4
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <8 x half> {{.*}}, splat (half 5.728130e+01)
-// NATIVE_HALF: ret <8 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <8 x float> {{.*}}, splat (float f0x42652EE1)
-// NO_HALF: ret <8 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <8 x half> {{.*}}, splat (half 5.728130e+01)
+// CHECK: ret <8 x half>
half2x4 test_degrees_half2x4(half2x4 p0) { return degrees(p0); }
// CHECK-LABEL: test_degrees_half3x1
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <3 x half> {{.*}}, splat (half 5.728130e+01)
-// NATIVE_HALF: ret <3 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <3 x float> {{.*}}, splat (float f0x42652EE1)
-// NO_HALF: ret <3 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <3 x half> {{.*}}, splat (half 5.728130e+01)
+// CHECK: ret <3 x half>
half3x1 test_degrees_half3x1(half3x1 p0) { return degrees(p0); }
// CHECK-LABEL: test_degrees_half3x2
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <6 x half> {{.*}}, splat (half 5.728130e+01)
-// NATIVE_HALF: ret <6 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <6 x float> {{.*}}, splat (float f0x42652EE1)
-// NO_HALF: ret <6 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <6 x half> {{.*}}, splat (half 5.728130e+01)
+// CHECK: ret <6 x half>
half3x2 test_degrees_half3x2(half3x2 p0) { return degrees(p0); }
// CHECK-LABEL: test_degrees_half3x3
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <9 x half> {{.*}}, splat (half 5.728130e+01)
-// NATIVE_HALF: ret <9 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <9 x float> {{.*}}, splat (float f0x42652EE1)
-// NO_HALF: ret <9 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <9 x half> {{.*}}, splat (half 5.728130e+01)
+// CHECK: ret <9 x half>
half3x3 test_degrees_half3x3(half3x3 p0) { return degrees(p0); }
// CHECK-LABEL: test_degrees_half3x4
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <12 x half> {{.*}}, splat (half 5.728130e+01)
-// NATIVE_HALF: ret <12 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <12 x float> {{.*}}, splat (float f0x42652EE1)
-// NO_HALF: ret <12 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <12 x half> {{.*}}, splat (half 5.728130e+01)
+// CHECK: ret <12 x half>
half3x4 test_degrees_half3x4(half3x4 p0) { return degrees(p0); }
// CHECK-LABEL: test_degrees_half4x1
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 5.728130e+01)
-// NATIVE_HALF: ret <4 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x42652EE1)
-// NO_HALF: ret <4 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 5.728130e+01)
+// CHECK: ret <4 x half>
half4x1 test_degrees_half4x1(half4x1 p0) { return degrees(p0); }
// CHECK-LABEL: test_degrees_half4x2
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <8 x half> {{.*}}, splat (half 5.728130e+01)
-// NATIVE_HALF: ret <8 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <8 x float> {{.*}}, splat (float f0x42652EE1)
-// NO_HALF: ret <8 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <8 x half> {{.*}}, splat (half 5.728130e+01)
+// CHECK: ret <8 x half>
half4x2 test_degrees_half4x2(half4x2 p0) { return degrees(p0); }
// CHECK-LABEL: test_degrees_half4x3
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <12 x half> {{.*}}, splat (half 5.728130e+01)
-// NATIVE_HALF: ret <12 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <12 x float> {{.*}}, splat (float f0x42652EE1)
-// NO_HALF: ret <12 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <12 x half> {{.*}}, splat (half 5.728130e+01)
+// CHECK: ret <12 x half>
half4x3 test_degrees_half4x3(half4x3 p0) { return degrees(p0); }
// CHECK-LABEL: test_degrees_half4x4
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <16 x half> {{.*}}, splat (half 5.728130e+01)
-// NATIVE_HALF: ret <16 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <16 x float> {{.*}}, splat (float f0x42652EE1)
-// NO_HALF: ret <16 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <16 x half> {{.*}}, splat (half 5.728130e+01)
+// CHECK: ret <16 x half>
half4x4 test_degrees_half4x4(half4x4 p0) { return degrees(p0); }
// CHECK-LABEL: test_degrees_float1x2
diff --git a/clang/test/CodeGenHLSL/builtins/radians_mat.hlsl b/clang/test/CodeGenHLSL/builtins/radians_mat.hlsl
index 60f55f20f7326..231e8b5ea0258 100644
--- a/clang/test/CodeGenHLSL/builtins/radians_mat.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/radians_mat.hlsl
@@ -1,121 +1,81 @@
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
// RUN: dxil-pc-shadermodel6.3-library %s \
// RUN: -fnative-half-type -fnative-int16-type -emit-llvm -o - \
-// RUN: | FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -o - \
-// RUN: | FileCheck %s --check-prefixes=CHECK,NO_HALF
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN: spirv-unknown-vulkan-library %s \
-// RUN: -fnative-half-type -fnative-int16-type -emit-llvm -o - \
-// RUN: | FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN: spirv-unknown-vulkan-library %s -emit-llvm -o - \
-// RUN: | FileCheck %s --check-prefixes=CHECK,NO_HALF
+// RUN: | FileCheck %s
// CHECK-LABEL: test_radians_half1x2
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <2 x half> {{.*}}, splat (half 1.745610e-02)
-// NATIVE_HALF: ret <2 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <2 x float> {{.*}}, splat (float f0x3C8EFA35)
-// NO_HALF: ret <2 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <2 x half> {{.*}}, splat (half 1.745610e-02)
+// CHECK: ret <2 x half>
half1x2 test_radians_half1x2(half1x2 p0) { return radians(p0); }
// CHECK-LABEL: test_radians_half1x3
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <3 x half> {{.*}}, splat (half 1.745610e-02)
-// NATIVE_HALF: ret <3 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <3 x float> {{.*}}, splat (float f0x3C8EFA35)
-// NO_HALF: ret <3 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <3 x half> {{.*}}, splat (half 1.745610e-02)
+// CHECK: ret <3 x half>
half1x3 test_radians_half1x3(half1x3 p0) { return radians(p0); }
// CHECK-LABEL: test_radians_half1x4
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 1.745610e-02)
-// NATIVE_HALF: ret <4 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x3C8EFA35)
-// NO_HALF: ret <4 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 1.745610e-02)
+// CHECK: ret <4 x half>
half1x4 test_radians_half1x4(half1x4 p0) { return radians(p0); }
// CHECK-LABEL: test_radians_half2x1
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <2 x half> {{.*}}, splat (half 1.745610e-02)
-// NATIVE_HALF: ret <2 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <2 x float> {{.*}}, splat (float f0x3C8EFA35)
-// NO_HALF: ret <2 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <2 x half> {{.*}}, splat (half 1.745610e-02)
+// CHECK: ret <2 x half>
half2x1 test_radians_half2x1(half2x1 p0) { return radians(p0); }
// CHECK-LABEL: test_radians_half2x2
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 1.745610e-02)
-// NATIVE_HALF: ret <4 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x3C8EFA35)
-// NO_HALF: ret <4 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 1.745610e-02)
+// CHECK: ret <4 x half>
half2x2 test_radians_half2x2(half2x2 p0) { return radians(p0); }
// CHECK-LABEL: test_radians_half2x3
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <6 x half> {{.*}}, splat (half 1.745610e-02)
-// NATIVE_HALF: ret <6 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <6 x float> {{.*}}, splat (float f0x3C8EFA35)
-// NO_HALF: ret <6 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <6 x half> {{.*}}, splat (half 1.745610e-02)
+// CHECK: ret <6 x half>
half2x3 test_radians_half2x3(half2x3 p0) { return radians(p0); }
// CHECK-LABEL: test_radians_half2x4
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <8 x half> {{.*}}, splat (half 1.745610e-02)
-// NATIVE_HALF: ret <8 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <8 x float> {{.*}}, splat (float f0x3C8EFA35)
-// NO_HALF: ret <8 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <8 x half> {{.*}}, splat (half 1.745610e-02)
+// CHECK: ret <8 x half>
half2x4 test_radians_half2x4(half2x4 p0) { return radians(p0); }
// CHECK-LABEL: test_radians_half3x1
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <3 x half> {{.*}}, splat (half 1.745610e-02)
-// NATIVE_HALF: ret <3 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <3 x float> {{.*}}, splat (float f0x3C8EFA35)
-// NO_HALF: ret <3 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <3 x half> {{.*}}, splat (half 1.745610e-02)
+// CHECK: ret <3 x half>
half3x1 test_radians_half3x1(half3x1 p0) { return radians(p0); }
// CHECK-LABEL: test_radians_half3x2
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <6 x half> {{.*}}, splat (half 1.745610e-02)
-// NATIVE_HALF: ret <6 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <6 x float> {{.*}}, splat (float f0x3C8EFA35)
-// NO_HALF: ret <6 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <6 x half> {{.*}}, splat (half 1.745610e-02)
+// CHECK: ret <6 x half>
half3x2 test_radians_half3x2(half3x2 p0) { return radians(p0); }
// CHECK-LABEL: test_radians_half3x3
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <9 x half> {{.*}}, splat (half 1.745610e-02)
-// NATIVE_HALF: ret <9 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <9 x float> {{.*}}, splat (float f0x3C8EFA35)
-// NO_HALF: ret <9 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <9 x half> {{.*}}, splat (half 1.745610e-02)
+// CHECK: ret <9 x half>
half3x3 test_radians_half3x3(half3x3 p0) { return radians(p0); }
// CHECK-LABEL: test_radians_half3x4
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <12 x half> {{.*}}, splat (half 1.745610e-02)
-// NATIVE_HALF: ret <12 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <12 x float> {{.*}}, splat (float f0x3C8EFA35)
-// NO_HALF: ret <12 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <12 x half> {{.*}}, splat (half 1.745610e-02)
+// CHECK: ret <12 x half>
half3x4 test_radians_half3x4(half3x4 p0) { return radians(p0); }
// CHECK-LABEL: test_radians_half4x1
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 1.745610e-02)
-// NATIVE_HALF: ret <4 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <4 x float> {{.*}}, splat (float f0x3C8EFA35)
-// NO_HALF: ret <4 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <4 x half> {{.*}}, splat (half 1.745610e-02)
+// CHECK: ret <4 x half>
half4x1 test_radians_half4x1(half4x1 p0) { return radians(p0); }
// CHECK-LABEL: test_radians_half4x2
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <8 x half> {{.*}}, splat (half 1.745610e-02)
-// NATIVE_HALF: ret <8 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <8 x float> {{.*}}, splat (float f0x3C8EFA35)
-// NO_HALF: ret <8 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <8 x half> {{.*}}, splat (half 1.745610e-02)
+// CHECK: ret <8 x half>
half4x2 test_radians_half4x2(half4x2 p0) { return radians(p0); }
// CHECK-LABEL: test_radians_half4x3
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <12 x half> {{.*}}, splat (half 1.745610e-02)
-// NATIVE_HALF: ret <12 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <12 x float> {{.*}}, splat (float f0x3C8EFA35)
-// NO_HALF: ret <12 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <12 x half> {{.*}}, splat (half 1.745610e-02)
+// CHECK: ret <12 x half>
half4x3 test_radians_half4x3(half4x3 p0) { return radians(p0); }
// CHECK-LABEL: test_radians_half4x4
-// NATIVE_HALF: fmul reassoc nnan ninf nsz arcp afn <16 x half> {{.*}}, splat (half 1.745610e-02)
-// NATIVE_HALF: ret <16 x half>
-// NO_HALF: fmul reassoc nnan ninf nsz arcp afn <16 x float> {{.*}}, splat (float f0x3C8EFA35)
-// NO_HALF: ret <16 x float>
+// CHECK: fmul reassoc nnan ninf nsz arcp afn <16 x half> {{.*}}, splat (half 1.745610e-02)
+// CHECK: ret <16 x half>
half4x4 test_radians_half4x4(half4x4 p0) { return radians(p0); }
// CHECK-LABEL: test_radians_float1x2
>From 2093a48e96ed0b671403451bc0a1bb2fe5f090a7 Mon Sep 17 00:00:00 2001
From: danbrown-amd <danbrown at amd.com>
Date: Wed, 26 Aug 2026 15:43:59 -0600
Subject: [PATCH 3/3] Move definitions to HLSLIntrinsics.td
---
clang/include/clang/Basic/HLSLIntrinsics.td | 6 ++++--
clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h | 8 --------
2 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/clang/include/clang/Basic/HLSLIntrinsics.td b/clang/include/clang/Basic/HLSLIntrinsics.td
index ba2ced302631e..9c1b133a9f81a 100644
--- a/clang/include/clang/Basic/HLSLIntrinsics.td
+++ b/clang/include/clang/Basic/HLSLIntrinsics.td
@@ -694,7 +694,7 @@ prevision partial derivative of the input value.
}
// Converts the specified value from radians to degrees.
-def hlsl_degrees : HLSLOneArgDetail<"degrees", "degrees_impl"> {
+def hlsl_degrees : HLSLOneArgInlineBuiltin<"degrees"> {
let Doc = [{
\fn T degrees(T x)
\brief Converts the specified value from radians to degrees.
@@ -702,6 +702,7 @@ def hlsl_degrees : HLSLOneArgDetail<"degrees", "degrees_impl"> {
}];
let ParamNames = ["x"];
let VaryingTypes = [HalfTy, FloatTy];
+ let Body = "return x * (__detail::elem_type_t<decltype(x)>)(180.L / __detail::Pi);";
}
// Returns the cross product of two floating-point, 3D vectors.
def hlsl_cross : HLSLTwoArgDetail<"cross", "cross_impl"> {
@@ -1391,13 +1392,14 @@ def hlsl_quad_read_across_diagonal : HLSLOneArgBuiltin<"QuadReadAcrossDiagonal",
}
// Converts the specified value from degrees to radians.
-def hlsl_radians : HLSLOneArgDetail<"radians", "radians_impl"> {
+def hlsl_radians : HLSLOneArgInlineBuiltin<"radians"> {
let Doc = [{
\fn T radians(T Val)
\brief Converts the specified value from degrees to radians.
}];
let ParamNames = ["Val"];
let VaryingTypes = [HalfTy, FloatTy];
+ let Body = "return Val * (__detail::elem_type_t<decltype(Val)>)(__detail::Pi / 180.L);";
}
// Calculates a fast, approximate, per-component reciprocal ie 1 / x.
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
index 9bf3e0298cf09..d96199f206504 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
@@ -180,14 +180,6 @@ template <typename T> constexpr T fwidth_impl(T input) {
#endif
}
-template <typename T> constexpr T degrees_impl(T Val) {
- return Val * (elem_type_t<T>)(180.L / Pi);
-}
-
-template <typename T> constexpr T radians_impl(T Val) {
- return Val * (elem_type_t<T>)(Pi / 180.L);
-}
-
} // namespace __detail
} // namespace hlsl
More information about the cfe-commits
mailing list