Skip to content

Commit 861dc29

Browse files
authored
[Headers][X86] Allow AVX vector concatenation intrinsics to be used in constexpr (#158020)
Fix #157705 Vector concatentation intrinsics made constexpr and test coverage added to avx-builtins.c for the following: ``` _mm256_set_m128 _mm256_setr_m128 _mm256_set_m128d _mm256_setr_m128d _mm256_set_m128i _mm256_setr_m128i ```
1 parent 75099c2 commit 861dc29

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

clang/lib/Headers/avxintrin.h

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4822,9 +4822,8 @@ _mm256_zextsi128_si256(__m128i __a) {
48224822
/// 128 bits of the result.
48234823
/// \returns A 256-bit floating-point vector of [8 x float] containing the
48244824
/// concatenated result.
4825-
static __inline __m256 __DEFAULT_FN_ATTRS
4826-
_mm256_set_m128 (__m128 __hi, __m128 __lo)
4827-
{
4825+
static __inline __m256 __DEFAULT_FN_ATTRS_CONSTEXPR
4826+
_mm256_set_m128(__m128 __hi, __m128 __lo) {
48284827
return (__m256) __builtin_shufflevector((__v4sf)__lo, (__v4sf)__hi, 0, 1, 2, 3, 4, 5, 6, 7);
48294828
}
48304829

@@ -4843,9 +4842,8 @@ _mm256_set_m128 (__m128 __hi, __m128 __lo)
48434842
/// 128 bits of the result.
48444843
/// \returns A 256-bit floating-point vector of [4 x double] containing the
48454844
/// concatenated result.
4846-
static __inline __m256d __DEFAULT_FN_ATTRS
4847-
_mm256_set_m128d (__m128d __hi, __m128d __lo)
4848-
{
4845+
static __inline __m256d __DEFAULT_FN_ATTRS_CONSTEXPR
4846+
_mm256_set_m128d(__m128d __hi, __m128d __lo) {
48494847
return (__m256d) __builtin_shufflevector((__v2df)__lo, (__v2df)__hi, 0, 1, 2, 3);
48504848
}
48514849

@@ -4863,9 +4861,8 @@ _mm256_set_m128d (__m128d __hi, __m128d __lo)
48634861
/// A 128-bit integer vector to be copied to the lower 128 bits of the
48644862
/// result.
48654863
/// \returns A 256-bit integer vector containing the concatenated result.
4866-
static __inline __m256i __DEFAULT_FN_ATTRS
4867-
_mm256_set_m128i (__m128i __hi, __m128i __lo)
4868-
{
4864+
static __inline __m256i __DEFAULT_FN_ATTRS_CONSTEXPR
4865+
_mm256_set_m128i(__m128i __hi, __m128i __lo) {
48694866
return (__m256i) __builtin_shufflevector((__v2di)__lo, (__v2di)__hi, 0, 1, 2, 3);
48704867
}
48714868

@@ -4886,9 +4883,8 @@ _mm256_set_m128i (__m128i __hi, __m128i __lo)
48864883
/// 128 bits of the result.
48874884
/// \returns A 256-bit floating-point vector of [8 x float] containing the
48884885
/// concatenated result.
4889-
static __inline __m256 __DEFAULT_FN_ATTRS
4890-
_mm256_setr_m128 (__m128 __lo, __m128 __hi)
4891-
{
4886+
static __inline __m256 __DEFAULT_FN_ATTRS_CONSTEXPR
4887+
_mm256_setr_m128(__m128 __lo, __m128 __hi) {
48924888
return _mm256_set_m128(__hi, __lo);
48934889
}
48944890

@@ -4909,9 +4905,8 @@ _mm256_setr_m128 (__m128 __lo, __m128 __hi)
49094905
/// 128 bits of the result.
49104906
/// \returns A 256-bit floating-point vector of [4 x double] containing the
49114907
/// concatenated result.
4912-
static __inline __m256d __DEFAULT_FN_ATTRS
4913-
_mm256_setr_m128d (__m128d __lo, __m128d __hi)
4914-
{
4908+
static __inline __m256d __DEFAULT_FN_ATTRS_CONSTEXPR
4909+
_mm256_setr_m128d(__m128d __lo, __m128d __hi) {
49154910
return (__m256d)_mm256_set_m128d(__hi, __lo);
49164911
}
49174912

@@ -4930,9 +4925,8 @@ _mm256_setr_m128d (__m128d __lo, __m128d __hi)
49304925
/// A 128-bit integer vector to be copied to the upper 128 bits of the
49314926
/// result.
49324927
/// \returns A 256-bit integer vector containing the concatenated result.
4933-
static __inline __m256i __DEFAULT_FN_ATTRS
4934-
_mm256_setr_m128i (__m128i __lo, __m128i __hi)
4935-
{
4928+
static __inline __m256i __DEFAULT_FN_ATTRS_CONSTEXPR
4929+
_mm256_setr_m128i(__m128i __lo, __m128i __hi) {
49364930
return (__m256i)_mm256_set_m128i(__hi, __lo);
49374931
}
49384932

clang/test/CodeGen/X86/avx-builtins.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,18 +1540,21 @@ __m256 test_mm256_set_m128(__m128 A, __m128 B) {
15401540
// CHECK: shufflevector <4 x float> %{{.*}}, <4 x float> %{{.*}}, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
15411541
return _mm256_set_m128(A, B);
15421542
}
1543+
TEST_CONSTEXPR(match_m256(_mm256_set_m128((__m128){10.0f, 20.0f, 30.0f, 40.0f}, (__m128){1.0f, 2.0f, 3.0f, 4.0f}), 1.0f, 2.0f, 3.0f, 4.0f, 10.0f, 20.0f, 30.0f, 40.0f));
15431544

15441545
__m256d test_mm256_set_m128d(__m128d A, __m128d B) {
15451546
// CHECK-LABEL: test_mm256_set_m128d
15461547
// CHECK: shufflevector <2 x double> %{{.*}}, <2 x double> %{{.*}}, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
15471548
return _mm256_set_m128d(A, B);
15481549
}
1550+
TEST_CONSTEXPR(match_m256d(_mm256_set_m128d((__m128d){10.0, 20.0}, (__m128d){1.0, 2.0}), 1.0, 2.0, 10.0, 20.0));
15491551

15501552
__m256i test_mm256_set_m128i(__m128i A, __m128i B) {
15511553
// CHECK-LABEL: test_mm256_set_m128i
15521554
// CHECK: shufflevector <2 x i64> %{{.*}}, <2 x i64> %{{.*}}, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
15531555
return _mm256_set_m128i(A, B);
15541556
}
1557+
TEST_CONSTEXPR(match_m256i(_mm256_set_m128i((__m128i){10LL, 20LL}, (__m128i){1LL, 2LL}), 1LL, 2LL, 10LL, 20LL));
15551558

15561559
__m256d test_mm256_set_pd(double A0, double A1, double A2, double A3) {
15571560
// CHECK-LABEL: test_mm256_set_pd
@@ -1778,18 +1781,21 @@ __m256 test_mm256_setr_m128(__m128 A, __m128 B) {
17781781
// CHECK: shufflevector <4 x float> %{{.*}}, <4 x float> %{{.*}}, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
17791782
return _mm256_setr_m128(A, B);
17801783
}
1784+
TEST_CONSTEXPR(match_m256(_mm256_setr_m128((__m128){1.0f, 2.0f, 3.0f, 4.0f}, (__m128){10.0f, 20.0f, 30.0f, 40.0f}), 1.0f, 2.0f, 3.0f, 4.0f, 10.0f, 20.0f, 30.0f, 40.0f));
17811785

17821786
__m256d test_mm256_setr_m128d(__m128d A, __m128d B) {
17831787
// CHECK-LABEL: test_mm256_setr_m128d
17841788
// CHECK: shufflevector <2 x double> %{{.*}}, <2 x double> %{{.*}}, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
17851789
return _mm256_setr_m128d(A, B);
17861790
}
1791+
TEST_CONSTEXPR(match_m256d(_mm256_setr_m128d((__m128d){1.0, 2.0}, (__m128d){10.0, 20.0}), 1.0, 2.0, 10.0, 20.0));
17871792

17881793
__m256i test_mm256_setr_m128i(__m128i A, __m128i B) {
17891794
// CHECK-LABEL: test_mm256_setr_m128i
17901795
// CHECK: shufflevector <2 x i64> %{{.*}}, <2 x i64> %{{.*}}, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
17911796
return _mm256_setr_m128i(A, B);
17921797
}
1798+
TEST_CONSTEXPR(match_m256i(_mm256_setr_m128i((__m128i){1LL, 2LL}, (__m128i){10LL, 20LL}), 1LL, 2LL, 10LL, 20LL));
17931799

17941800
__m256d test_mm256_setr_pd(double A0, double A1, double A2, double A3) {
17951801
// CHECK-LABEL: test_mm256_setr_pd

0 commit comments

Comments
 (0)