Skip to content

Commit

Permalink
[Headers][X86] Ensure all AVX broadcast scalar load intrinsics are un…
Browse files Browse the repository at this point in the history
…aligned

Similar to the existing _mm_load1_pd/_mm_loaddup_pd and broadcast vector loads, these intrinsic should ensure the loads are unaligned and not assume type alignment

Fixes #62325
  • Loading branch information
RKSimon committed Jul 3, 2023
1 parent f292ca1 commit d963420
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 13 additions & 4 deletions clang/lib/Headers/avxintrin.h
Original file line number Diff line number Diff line change
Expand Up @@ -3017,8 +3017,11 @@ _mm256_zeroupper(void)
static __inline __m128 __DEFAULT_FN_ATTRS128
_mm_broadcast_ss(float const *__a)
{
float __f = *__a;
return __extension__ (__m128)(__v4sf){ __f, __f, __f, __f };
struct __mm_broadcast_ss_struct {
float __f;
} __attribute__((__packed__, __may_alias__));
float __f = ((const struct __mm_broadcast_ss_struct*)__a)->__f;
return __extension__ (__m128){ __f, __f, __f, __f };
}

/// Loads a scalar double-precision floating point value from the
Expand All @@ -3036,7 +3039,10 @@ _mm_broadcast_ss(float const *__a)
static __inline __m256d __DEFAULT_FN_ATTRS
_mm256_broadcast_sd(double const *__a)
{
double __d = *__a;
struct __mm256_broadcast_sd_struct {
double __d;
} __attribute__((__packed__, __may_alias__));
double __d = ((const struct __mm256_broadcast_sd_struct*)__a)->__d;
return __extension__ (__m256d)(__v4df){ __d, __d, __d, __d };
}

Expand All @@ -3055,7 +3061,10 @@ _mm256_broadcast_sd(double const *__a)
static __inline __m256 __DEFAULT_FN_ATTRS
_mm256_broadcast_ss(float const *__a)
{
float __f = *__a;
struct __mm256_broadcast_ss_struct {
float __f;
} __attribute__((__packed__, __may_alias__));
float __f = ((const struct __mm256_broadcast_ss_struct*)__a)->__f;
return __extension__ (__m256)(__v8sf){ __f, __f, __f, __f, __f, __f, __f, __f };
}

Expand Down
6 changes: 3 additions & 3 deletions clang/test/CodeGen/X86/avx-builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ __m256 test_mm256_broadcast_ps(__m128* A) {

__m256d test_mm256_broadcast_sd(double* A) {
// CHECK-LABEL: test_mm256_broadcast_sd
// CHECK: load double, ptr %{{.*}}
// CHECK: load double, ptr %{{.*}}, align 1{{$}}
// CHECK: insertelement <4 x double> undef, double %{{.*}}, i32 0
// CHECK: insertelement <4 x double> %{{.*}}, double %{{.*}}, i32 1
// CHECK: insertelement <4 x double> %{{.*}}, double %{{.*}}, i32 2
Expand All @@ -109,7 +109,7 @@ __m256d test_mm256_broadcast_sd(double* A) {

__m128 test_mm_broadcast_ss(float* A) {
// CHECK-LABEL: test_mm_broadcast_ss
// CHECK: load float, ptr %{{.*}}
// CHECK: load float, ptr %{{.*}}, align 1{{$}}
// CHECK: insertelement <4 x float> undef, float %{{.*}}, i32 0
// CHECK: insertelement <4 x float> %{{.*}}, float %{{.*}}, i32 1
// CHECK: insertelement <4 x float> %{{.*}}, float %{{.*}}, i32 2
Expand All @@ -119,7 +119,7 @@ __m128 test_mm_broadcast_ss(float* A) {

__m256 test_mm256_broadcast_ss(float* A) {
// CHECK-LABEL: test_mm256_broadcast_ss
// CHECK: load float, ptr %{{.*}}
// CHECK: load float, ptr %{{.*}}, align 1{{$}}
// CHECK: insertelement <8 x float> undef, float %{{.*}}, i32 0
// CHECK: insertelement <8 x float> %{{.*}}, float %{{.*}}, i32 1
// CHECK: insertelement <8 x float> %{{.*}}, float %{{.*}}, i32 2
Expand Down

0 comments on commit d963420

Please sign in to comment.