[clang] [clang] Make vector cast intrinsics constexpr (PR #156380)
llvmbot wrote:
@llvm/pr-subscribers-clang
Author: None (vedantjk)
Changes
Enable constexpr usage of vector bitcast intrinsics by changing from
`__DEFAULT_FN_ATTRS*` to
`__DEFAULT_FN_ATTRS*_CONSTEXPR` attributes.
**Updated intrinsics:**
- AVX-512 bitcast intrinsics: `_mm512_castpd_ps`, `_mm512_castps_pd`,
`_mm512_cast*_si512`,
`_mm512_castsi512_*`
- AVX-512 truncation casts: `_mm512_cast*512_*128/256`
- AVX-512 FP16 bitcast intrinsics: all `_mm*_castph_*` and `_mm*_cast*_ph`
functions
- AVX-512 FP16 truncation casts: `_mm*_castph*_ph*`
github.com/llvm/llvm-project/issues/156348
---
Full diff: https://github.com/llvm/llvm-project/pull/156380.diff
2 Files Affected:
- (modified) clang/lib/Headers/avx512fintrin.h (+12-12)
- (modified) clang/lib/Headers/avx512fp16intrin.h (+21-21)
``diff
diff --git a/clang/lib/Headers/avx512fintrin.h
b/clang/lib/Headers/avx512fintrin.h
index a525652e1e15a..c74e1087c5316 100644
--- a/clang/lib/Headers/avx512fintrin.h
+++ b/clang/lib/Headers/avx512fintrin.h
@@ -408,37 +408,37 @@ _mm512_castps256_ps512(__m256 __a)
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15);
}
-static __inline __m128d __DEFAULT_FN_ATTRS512
+static __inline __m128d __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castpd512_pd128(__m512d __a)
{
return __builtin_shufflevector(__a, __a, 0, 1);
}
-static __inline __m256d __DEFAULT_FN_ATTRS512
+static __inline __m256d __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castpd512_pd256 (__m512d __A)
{
return __builtin_shufflevector(__A, __A, 0, 1, 2, 3);
}
-static __inline __m128 __DEFAULT_FN_ATTRS512
+static __inline __m128 __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castps512_ps128(__m512 __a)
{
return __builtin_shufflevector(__a, __a, 0, 1, 2, 3);
}
-static __inline __m256 __DEFAULT_FN_ATTRS512
+static __inline __m256 __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castps512_ps256 (__m512 __A)
{
return __builtin_shufflevector(__A, __A, 0, 1, 2, 3, 4, 5, 6, 7);
}
-static __inline __m512 __DEFAULT_FN_ATTRS512
+static __inline __m512 __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castpd_ps (__m512d __A)
{
return (__m512) (__A);
}
-static __inline __m512i __DEFAULT_FN_ATTRS512
+static __inline __m512i __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castpd_si512 (__m512d __A)
{
return (__m512i) (__A);
@@ -453,13 +453,13 @@ _mm512_castpd128_pd512 (__m128d __A)
__B, 0, 1, 2, 3, 4, 5, 6, 7);
}
-static __inline __m512d __DEFAULT_FN_ATTRS512
+static __inline __m512d __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castps_pd (__m512 __A)
{
return (__m512d) (__A);
}
-static __inline __m512i __DEFAULT_FN_ATTRS512
+static __inline __m512i __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castps_si512 (__m512 __A)
{
return (__m512i) (__A);
@@ -489,25 +489,25 @@ _mm512_castsi256_si512 (__m256i __A)
return __builtin_shufflevector( __A,
__builtin_nondeterministic_value(__A), 0, 1, 2, 3, 4, 5, 6, 7);
}
-static __inline __m512 __DEFAULT_FN_ATTRS512
+static __inline __m512 __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castsi512_ps (__m512i __A)
{
return (__m512) (__A);
}
-static __inline __m512d __DEFAULT_FN_ATTRS512
+static __inline __m512d __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castsi512_pd (__m512i __A)
{
return (__m512d) (__A);
}
-static __inline __m128i __DEFAULT_FN_ATTRS512
+static __inline __m128i __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castsi512_si128 (__m512i __A)
{
return (__m128i)__builtin_shufflevector(__A, __A , 0, 1);
}
-static __inline __m256i __DEFAULT_FN_ATTRS512
+static __inline __m256i __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castsi512_si256 (__m512i __A)
{
return (__m256i)__builtin_shufflevector(__A, __A , 0, 1, 2, 3);
diff --git a/clang/lib/Headers/avx512fp16intrin.h
b/clang/lib/Headers/avx512fp16intrin.h
index 6989b86a7b68c..b8145613d06fe 100644
--- a/clang/lib/Headers/avx512fp16intrin.h
+++ b/clang/lib/Headers/avx512fp16intrin.h
@@ -113,93 +113,93 @@ _mm512_set1_pch(_Float16 _Complex __h) {
return (__m512h)_mm512_set1_ps(__builtin_bit_cast(float, __h));
}
-static __inline__ __m128 __DEFAULT_FN_ATTRS128 _mm_castph_ps(__m128h __a) {
+static __inline__ __m128 __DEFAULT_FN_ATTRS128_CONSTEXPR _mm_castph_ps(__m128h
__a) {
return (__m128)__a;
}
-static __inline__ __m256 __DEFAULT_FN_ATTRS256 _mm256_castph_ps(__m256h __a) {
+static __inline__ __m256 __DEFAULT_FN_ATTRS256_CONSTEXPR
_mm256_castph_ps(__m256h __a) {
return (__m256)__a;
}
-static __inline__ __m512 __DEFAULT_FN_ATTRS512 _mm512_castph_ps(__m512h __a) {
+static __inline__ __m512 __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castph_ps(__m512h __a) {
return (__m512)__a;
}
-static __inline__ __m128d __DEFAULT_FN_ATTRS128 _mm_castph_pd(__m128h __a) {
+static __inline__ __m128d __DEFAULT_FN_ATTRS128_CONSTEXPR
_mm_castph_pd(__m128h __a) {
return (__m128d)__a;
}
-static __inline__ __m256d __DEFAULT_FN_ATTRS256 _mm256_castph_pd(__m256h __a) {
+static __inline__ __m256d
[clang] [clang] Make vector cast intrinsics constexpr (PR #156380)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/156380 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Make vector cast intrinsics constexpr (PR #156380)
https://github.com/vedantjk created
https://github.com/llvm/llvm-project/pull/156380
Enable constexpr usage of vector bitcast intrinsics by changing from
`__DEFAULT_FN_ATTRS*` to
`__DEFAULT_FN_ATTRS*_CONSTEXPR` attributes.
**Updated intrinsics:**
- AVX-512 bitcast intrinsics: `_mm512_castpd_ps`, `_mm512_castps_pd`,
`_mm512_cast*_si512`,
`_mm512_castsi512_*`
- AVX-512 truncation casts: `_mm512_cast*512_*128/256`
- AVX-512 FP16 bitcast intrinsics: all `_mm*_castph_*` and `_mm*_cast*_ph`
functions
- AVX-512 FP16 truncation casts: `_mm*_castph*_ph*`
github.com/llvm/llvm-project/issues/156348
>From a54599db951f08cbbf4f391facaeb5a874a17416 Mon Sep 17 00:00:00 2001
From: vedantjk
Date: Mon, 1 Sep 2025 17:47:39 -0700
Subject: [PATCH] [clang] Make vector cast intrinsics constexpr
---
clang/lib/Headers/avx512fintrin.h| 24
clang/lib/Headers/avx512fp16intrin.h | 42 ++--
2 files changed, 33 insertions(+), 33 deletions(-)
diff --git a/clang/lib/Headers/avx512fintrin.h
b/clang/lib/Headers/avx512fintrin.h
index a525652e1e15a..c74e1087c5316 100644
--- a/clang/lib/Headers/avx512fintrin.h
+++ b/clang/lib/Headers/avx512fintrin.h
@@ -408,37 +408,37 @@ _mm512_castps256_ps512(__m256 __a)
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15);
}
-static __inline __m128d __DEFAULT_FN_ATTRS512
+static __inline __m128d __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castpd512_pd128(__m512d __a)
{
return __builtin_shufflevector(__a, __a, 0, 1);
}
-static __inline __m256d __DEFAULT_FN_ATTRS512
+static __inline __m256d __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castpd512_pd256 (__m512d __A)
{
return __builtin_shufflevector(__A, __A, 0, 1, 2, 3);
}
-static __inline __m128 __DEFAULT_FN_ATTRS512
+static __inline __m128 __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castps512_ps128(__m512 __a)
{
return __builtin_shufflevector(__a, __a, 0, 1, 2, 3);
}
-static __inline __m256 __DEFAULT_FN_ATTRS512
+static __inline __m256 __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castps512_ps256 (__m512 __A)
{
return __builtin_shufflevector(__A, __A, 0, 1, 2, 3, 4, 5, 6, 7);
}
-static __inline __m512 __DEFAULT_FN_ATTRS512
+static __inline __m512 __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castpd_ps (__m512d __A)
{
return (__m512) (__A);
}
-static __inline __m512i __DEFAULT_FN_ATTRS512
+static __inline __m512i __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castpd_si512 (__m512d __A)
{
return (__m512i) (__A);
@@ -453,13 +453,13 @@ _mm512_castpd128_pd512 (__m128d __A)
__B, 0, 1, 2, 3, 4, 5, 6, 7);
}
-static __inline __m512d __DEFAULT_FN_ATTRS512
+static __inline __m512d __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castps_pd (__m512 __A)
{
return (__m512d) (__A);
}
-static __inline __m512i __DEFAULT_FN_ATTRS512
+static __inline __m512i __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castps_si512 (__m512 __A)
{
return (__m512i) (__A);
@@ -489,25 +489,25 @@ _mm512_castsi256_si512 (__m256i __A)
return __builtin_shufflevector( __A,
__builtin_nondeterministic_value(__A), 0, 1, 2, 3, 4, 5, 6, 7);
}
-static __inline __m512 __DEFAULT_FN_ATTRS512
+static __inline __m512 __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castsi512_ps (__m512i __A)
{
return (__m512) (__A);
}
-static __inline __m512d __DEFAULT_FN_ATTRS512
+static __inline __m512d __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castsi512_pd (__m512i __A)
{
return (__m512d) (__A);
}
-static __inline __m128i __DEFAULT_FN_ATTRS512
+static __inline __m128i __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castsi512_si128 (__m512i __A)
{
return (__m128i)__builtin_shufflevector(__A, __A , 0, 1);
}
-static __inline __m256i __DEFAULT_FN_ATTRS512
+static __inline __m256i __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castsi512_si256 (__m512i __A)
{
return (__m256i)__builtin_shufflevector(__A, __A , 0, 1, 2, 3);
diff --git a/clang/lib/Headers/avx512fp16intrin.h
b/clang/lib/Headers/avx512fp16intrin.h
index 6989b86a7b68c..b8145613d06fe 100644
--- a/clang/lib/Headers/avx512fp16intrin.h
+++ b/clang/lib/Headers/avx512fp16intrin.h
@@ -113,93 +113,93 @@ _mm512_set1_pch(_Float16 _Complex __h) {
return (__m512h)_mm512_set1_ps(__builtin_bit_cast(float, __h));
}
-static __inline__ __m128 __DEFAULT_FN_ATTRS128 _mm_castph_ps(__m128h __a) {
+static __inline__ __m128 __DEFAULT_FN_ATTRS128_CONSTEXPR _mm_castph_ps(__m128h
__a) {
return (__m128)__a;
}
-static __inline__ __m256 __DEFAULT_FN_ATTRS256 _mm256_castph_ps(__m256h __a) {
+static __inline__ __m256 __DEFAULT_FN_ATTRS256_CONSTEXPR
_mm256_castph_ps(__m256h __a) {
return (__m256)__a;
}
-static __inline__ __m512 __DEFAULT_FN_ATTRS512 _mm512_castph_ps(__m512h __a) {
+static __inline__ __m512 __DEFAULT_FN_ATTRS512_CONSTEXPR
_mm512_castph_ps(__m512h __a) {
return (__m512)__a;
}
-static __inline__ __m128d __DEFAULT_FN_ATTRS128 _mm_castph_pd(__m128h __a) {
+static __inline__ __m128d __DEFAULT_FN_ATTRS128_CONSTEXPR
_mm_castph_pd(__m128h
