https://github.com/farzonl created https://github.com/llvm/llvm-project/pull/222056
fixes #222055 A previous pr replaced per vector 2-4 overloads with an all inclusive vector template overload. These vector overloads needed to be guarded so that vec1s go down the scalar overload path. >From f2e9977d9ca6f6e9503818f0c9c4042b74755a2c Mon Sep 17 00:00:00 2001 From: Farzon Lotfi <[email protected]> Date: Tue, 8 Sep 2026 12:43:46 -0400 Subject: [PATCH] [HLSL] Fix float type promotion to double of the select intrinsic fixes #222055 A previous pr replaced per vector 2-4 overloads with an all inclusive vector template overload. These vector overloads needed to be guarded so that vec1s go down the scalar overload path. --- clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h | 12 ++++++------ clang/test/CodeGenHLSL/builtins/select.hlsl | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h index 772e740c264fd..30fa47b699f85 100644 --- a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h @@ -147,8 +147,8 @@ T select(bool, T, T); template <typename T, int N> _HLSL_BUILTIN_ALIAS(__builtin_hlsl_select) -vector<T, N> select(__detail::type_identity_t<vector<bool, N>>, vector<T, N>, - vector<T, N>); +__detail::enable_if_t<(N > 1), vector<T, N>> select( + __detail::type_identity_t<vector<bool, N>>, vector<T, N>, vector<T, N>); /// \fn vector<T,Sz> select(vector<bool,Sz> Conds, T TrueVal, /// vector<T,Sz> FalseVals) @@ -160,8 +160,8 @@ vector<T, N> select(__detail::type_identity_t<vector<bool, N>>, vector<T, N>, template <typename T, int N> _HLSL_BUILTIN_ALIAS(__builtin_hlsl_select) -vector<T, N> select(__detail::type_identity_t<vector<bool, N>>, T, - vector<T, N>); +__detail::enable_if_t<(N > 1), vector<T, N>> select( + __detail::type_identity_t<vector<bool, N>>, T, vector<T, N>); /// \fn vector<T,Sz> select(vector<bool,Sz> Conds, vector<T,Sz> TrueVals, /// T FalseVal) @@ -172,8 +172,8 @@ vector<T, N> select(__detail::type_identity_t<vector<bool, N>>, T, template <typename T, int N> _HLSL_BUILTIN_ALIAS(__builtin_hlsl_select) -vector<T, N> select(__detail::type_identity_t<vector<bool, N>>, vector<T, N>, - T); +__detail::enable_if_t<(N > 1), vector<T, N>> select( + __detail::type_identity_t<vector<bool, N>>, vector<T, N>, T); /// \fn vector<T,Sz> select(vector<bool,Sz> Conds, T TrueVals, /// T FalseVal) diff --git a/clang/test/CodeGenHLSL/builtins/select.hlsl b/clang/test/CodeGenHLSL/builtins/select.hlsl index 238beea0d4155..f9dc50227599e 100644 --- a/clang/test/CodeGenHLSL/builtins/select.hlsl +++ b/clang/test/CodeGenHLSL/builtins/select.hlsl @@ -28,12 +28,26 @@ int2 test_select_bool_vector(bool cond0, int2 tVal, int2 fVal) { } // CHECK-LABEL: test_select_vector_1 -// CHECK: [[SELECT:%.*]] = select <1 x i1> {{%.*}}, <1 x i32> {{%.*}}, <1 x i32> {{%.*}} +// CHECK: [[SELECT:%.*]] = select i1 {{%.*}}, <1 x i32> {{%.*}}, <1 x i32> {{%.*}} // CHECK: ret <1 x i32> [[SELECT]] int1 test_select_vector_1(bool1 cond0, int1 tVals, int1 fVals) { return select(cond0, tVals, fVals); } +// CHECK-LABEL: test_select_float_vector_1 +// CHECK: [[SELECT:%.*]] = select i1 {{%.*}}, <1 x float> {{%.*}}, <1 x float> {{%.*}} +// CHECK: ret <1 x float> [[SELECT]] +float1 test_select_float_vector_1(bool1 cond0, float1 tVals, float1 fVals) { + return select(cond0, tVals, fVals); +} + +// CHECK-LABEL: test_select_half_vector_1 +// CHECK: [[SELECT:%.*]] = select i1 {{%.*}}, <1 x half> {{%.*}}, <1 x half> {{%.*}} +// CHECK: ret <1 x half> [[SELECT]] +half1 test_select_half_vector_1(bool1 cond0, half1 tVals, half1 fVals) { + return select(cond0, tVals, fVals); +} + // CHECK-LABEL: test_select_vector_2 // CHECK: [[SELECT:%.*]] = select <2 x i1> {{%.*}}, <2 x i32> {{%.*}}, <2 x i32> {{%.*}} // CHECK: ret <2 x i32> [[SELECT]] _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
