[clang] [X86] avx512vlfp16intrin.h.h - allow _mm_cvtsh_h/_mm256_cvtsh_h to be used in constexpr (PR #162275)
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 7 05:30:33 PDT 2025
https://github.com/RKSimon created https://github.com/llvm/llvm-project/pull/162275
This was missed in the earlier f16c/fp16 constexpr patches
>From 97a39d346c469772b4fc2e8a9e75c83b56537212 Mon Sep 17 00:00:00 2001
From: Simon Pilgrim <llvm-dev at redking.me.uk>
Date: Tue, 7 Oct 2025 13:28:30 +0100
Subject: [PATCH] [X86] avx512vlfp16intrin.h.h - allow
_mm_cvtsh_h/_mm256_cvtsh_h to be used in constexpr
This was missed in the earlier f16c/fp16 constexpr patches
---
clang/lib/Headers/avx512vlfp16intrin.h | 6 ++++--
clang/test/CodeGen/X86/avx512vlfp16-builtins.c | 2 ++
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Headers/avx512vlfp16intrin.h b/clang/lib/Headers/avx512vlfp16intrin.h
index c0bcc080dbe93..5b2b3f0d0bbd4 100644
--- a/clang/lib/Headers/avx512vlfp16intrin.h
+++ b/clang/lib/Headers/avx512vlfp16intrin.h
@@ -34,11 +34,13 @@
#define __DEFAULT_FN_ATTRS128_CONSTEXPR __DEFAULT_FN_ATTRS128
#endif
-static __inline__ _Float16 __DEFAULT_FN_ATTRS128 _mm_cvtsh_h(__m128h __a) {
+static __inline__ _Float16 __DEFAULT_FN_ATTRS128_CONSTEXPR
+_mm_cvtsh_h(__m128h __a) {
return __a[0];
}
-static __inline__ _Float16 __DEFAULT_FN_ATTRS256 _mm256_cvtsh_h(__m256h __a) {
+static __inline__ _Float16 __DEFAULT_FN_ATTRS256_CONSTEXPR
+_mm256_cvtsh_h(__m256h __a) {
return __a[0];
}
diff --git a/clang/test/CodeGen/X86/avx512vlfp16-builtins.c b/clang/test/CodeGen/X86/avx512vlfp16-builtins.c
index f1865aae4a9e2..68d09849a317b 100644
--- a/clang/test/CodeGen/X86/avx512vlfp16-builtins.c
+++ b/clang/test/CodeGen/X86/avx512vlfp16-builtins.c
@@ -17,12 +17,14 @@ _Float16 test_mm_cvtsh_h(__m128h __A) {
// CHECK: extractelement <8 x half> %{{.*}}, i32 0
return _mm_cvtsh_h(__A);
}
+TEST_CONSTEXPR(_mm_cvtsh_h((__m128h){-8.0, 7.0, -6.0, 5.0, -4.0, 3.0, -2.0, 1.0}) == -8.0);
_Float16 test_mm256_cvtsh_h(__m256h __A) {
// CHECK-LABEL: test_mm256_cvtsh_h
// CHECK: extractelement <16 x half> %{{.*}}, i32 0
return _mm256_cvtsh_h(__A);
}
+TEST_CONSTEXPR(_mm256_cvtsh_h((__m256h){-32.0, 31.0, -30.0, 29.0, -28.0, 27.0, -26.0, 25.0, -24.0, 23.0, -22.0, 21.0, -20.0, 19.0, -18.0, 17.0}) == -32.0);
__m128h test_mm_set_sh(_Float16 __h) {
// CHECK-LABEL: test_mm_set_sh
More information about the cfe-commits
mailing list