[clang] b3ac5b8 - [SystemZ] Fix vecintrin.h to not emit alignment hints in vec_xl/vec_xst.

Jonas Paulsson via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 12 16:30:29 PST 2021


Author: Jonas Paulsson
Date: 2021-02-12T18:26:36-06:00
New Revision: b3ac5b84cdd46fc62a7215ae6b11f3c005900461

URL: https://github.com/llvm/llvm-project/commit/b3ac5b84cdd46fc62a7215ae6b11f3c005900461
DIFF: https://github.com/llvm/llvm-project/commit/b3ac5b84cdd46fc62a7215ae6b11f3c005900461.diff

LOG: [SystemZ] Fix vecintrin.h to not emit alignment hints in vec_xl/vec_xst.

vec_xl() and vec_xst() should not emit alignment hints since they take a
scalar pointer and also add a byte offset if passed.

This patch uses memcpy to achieve the desired result.

Review: Ulrich Weigand

Differential Revision: https://reviews.llvm.org/D96471

Added: 
    

Modified: 
    clang/lib/Headers/vecintrin.h
    clang/test/CodeGen/SystemZ/builtins-systemz-zvector-constrained.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Headers/vecintrin.h b/clang/lib/Headers/vecintrin.h
index e58c9769e8cb..1fd7436b2c60 100644
--- a/clang/lib/Headers/vecintrin.h
+++ b/clang/lib/Headers/vecintrin.h
@@ -1016,64 +1016,84 @@ vec_scatter_element(__vector double __vec,
 
 static inline __ATTRS_o_ai __vector signed char
 vec_xl(long __offset, const signed char *__ptr) {
-  return *(const __vector signed char *)
-          ((const char *)__ptr + __offset);
+  __vector signed char V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector signed char));
+  return V;
 }
 
 static inline __ATTRS_o_ai __vector unsigned char
 vec_xl(long __offset, const unsigned char *__ptr) {
-  return *(const __vector unsigned char *)
-          ((const char *)__ptr + __offset);
+  __vector unsigned char V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector unsigned char));
+  return V;
 }
 
 static inline __ATTRS_o_ai __vector signed short
 vec_xl(long __offset, const signed short *__ptr) {
-  return *(const __vector signed short *)
-          ((const char *)__ptr + __offset);
+  __vector signed short V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector signed short));
+  return V;
 }
 
 static inline __ATTRS_o_ai __vector unsigned short
 vec_xl(long __offset, const unsigned short *__ptr) {
-  return *(const __vector unsigned short *)
-          ((const char *)__ptr + __offset);
+  __vector unsigned short V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector unsigned short));
+  return V;
 }
 
 static inline __ATTRS_o_ai __vector signed int
 vec_xl(long __offset, const signed int *__ptr) {
-  return *(const __vector signed int *)
-          ((const char *)__ptr + __offset);
+  __vector signed int V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector signed int));
+  return V;
 }
 
 static inline __ATTRS_o_ai __vector unsigned int
 vec_xl(long __offset, const unsigned int *__ptr) {
-  return *(const __vector unsigned int *)
-          ((const char *)__ptr + __offset);
+  __vector unsigned int V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector unsigned int));
+  return V;
 }
 
 static inline __ATTRS_o_ai __vector signed long long
 vec_xl(long __offset, const signed long long *__ptr) {
-  return *(const __vector signed long long *)
-          ((const char *)__ptr + __offset);
+  __vector signed long long V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector signed long long));
+  return V;
 }
 
 static inline __ATTRS_o_ai __vector unsigned long long
 vec_xl(long __offset, const unsigned long long *__ptr) {
-  return *(const __vector unsigned long long *)
-          ((const char *)__ptr + __offset);
+  __vector unsigned long long V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector unsigned long long));
+  return V;
 }
 
 #if __ARCH__ >= 12
 static inline __ATTRS_o_ai __vector float
 vec_xl(long __offset, const float *__ptr) {
-  return *(const __vector float *)
-          ((const char *)__ptr + __offset);
+  __vector float V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector float));
+  return V;
 }
 #endif
 
 static inline __ATTRS_o_ai __vector double
 vec_xl(long __offset, const double *__ptr) {
-  return *(const __vector double *)
-          ((const char *)__ptr + __offset);
+  __vector double V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector double));
+  return V;
 }
 
 /*-- vec_xld2 ---------------------------------------------------------------*/
@@ -1081,64 +1101,82 @@ vec_xl(long __offset, const double *__ptr) {
 // This prototype is deprecated.
 static inline __ATTRS_o_ai __vector signed char
 vec_xld2(long __offset, const signed char *__ptr) {
-  return *(const __vector signed char *)
-          ((const char *)__ptr + __offset);
+  __vector signed char V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector signed char));
+  return V;
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai __vector unsigned char
 vec_xld2(long __offset, const unsigned char *__ptr) {
-  return *(const __vector unsigned char *)
-          ((const char *)__ptr + __offset);
+  __vector unsigned char V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector unsigned char));
+  return V;
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai __vector signed short
 vec_xld2(long __offset, const signed short *__ptr) {
-  return *(const __vector signed short *)
-          ((const char *)__ptr + __offset);
+  __vector signed short V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector signed short));
+  return V;
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai __vector unsigned short
 vec_xld2(long __offset, const unsigned short *__ptr) {
-  return *(const __vector unsigned short *)
-          ((const char *)__ptr + __offset);
+  __vector unsigned short V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector unsigned short));
+  return V;
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai __vector signed int
 vec_xld2(long __offset, const signed int *__ptr) {
-  return *(const __vector signed int *)
-          ((const char *)__ptr + __offset);
+  __vector signed int V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector signed int));
+  return V;
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai __vector unsigned int
 vec_xld2(long __offset, const unsigned int *__ptr) {
-  return *(const __vector unsigned int *)
-          ((const char *)__ptr + __offset);
+  __vector unsigned int V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector unsigned int));
+  return V;
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai __vector signed long long
 vec_xld2(long __offset, const signed long long *__ptr) {
-  return *(const __vector signed long long *)
-          ((const char *)__ptr + __offset);
+  __vector signed long long V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector signed long long));
+  return V;
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai __vector unsigned long long
 vec_xld2(long __offset, const unsigned long long *__ptr) {
-  return *(const __vector unsigned long long *)
-          ((const char *)__ptr + __offset);
+  __vector unsigned long long V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector unsigned long long));
+  return V;
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai __vector double
 vec_xld2(long __offset, const double *__ptr) {
-  return *(const __vector double *)
-          ((const char *)__ptr + __offset);
+  __vector double V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector double));
+  return V;
 }
 
 /*-- vec_xlw4 ---------------------------------------------------------------*/
@@ -1146,99 +1184,128 @@ vec_xld2(long __offset, const double *__ptr) {
 // This prototype is deprecated.
 static inline __ATTRS_o_ai __vector signed char
 vec_xlw4(long __offset, const signed char *__ptr) {
-  return *(const __vector signed char *)
-          ((const char *)__ptr + __offset);
+  __vector signed char V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector signed char));
+  return V;
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai __vector unsigned char
 vec_xlw4(long __offset, const unsigned char *__ptr) {
-  return *(const __vector unsigned char *)
-          ((const char *)__ptr + __offset);
+  __vector unsigned char V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector unsigned char));
+  return V;
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai __vector signed short
 vec_xlw4(long __offset, const signed short *__ptr) {
-  return *(const __vector signed short *)
-          ((const char *)__ptr + __offset);
+  __vector signed short V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector signed short));
+  return V;
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai __vector unsigned short
 vec_xlw4(long __offset, const unsigned short *__ptr) {
-  return *(const __vector unsigned short *)
-          ((const char *)__ptr + __offset);
+  __vector unsigned short V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector unsigned short));
+  return V;
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai __vector signed int
 vec_xlw4(long __offset, const signed int *__ptr) {
-  return *(const __vector signed int *)
-          ((const char *)__ptr + __offset);
+  __vector signed int V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector signed int));
+  return V;
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai __vector unsigned int
 vec_xlw4(long __offset, const unsigned int *__ptr) {
-  return *(const __vector unsigned int *)
-          ((const char *)__ptr + __offset);
+  __vector unsigned int V;
+  __builtin_memcpy(&V, ((const char *)__ptr + __offset),
+                   sizeof(__vector unsigned int));
+  return V;
 }
 
 /*-- vec_xst ----------------------------------------------------------------*/
 
 static inline __ATTRS_o_ai void
 vec_xst(__vector signed char __vec, long __offset, signed char *__ptr) {
-  *(__vector signed char *)((char *)__ptr + __offset) = __vec;
+  __vector signed char V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector signed char));
 }
 
 static inline __ATTRS_o_ai void
 vec_xst(__vector unsigned char __vec, long __offset, unsigned char *__ptr) {
-  *(__vector unsigned char *)((char *)__ptr + __offset) = __vec;
+  __vector unsigned char V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector unsigned char));
 }
 
 static inline __ATTRS_o_ai void
 vec_xst(__vector signed short __vec, long __offset, signed short *__ptr) {
-  *(__vector signed short *)((char *)__ptr + __offset) = __vec;
+  __vector signed short V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector signed short));
 }
 
 static inline __ATTRS_o_ai void
 vec_xst(__vector unsigned short __vec, long __offset, unsigned short *__ptr) {
-  *(__vector unsigned short *)((char *)__ptr + __offset) = __vec;
+  __vector unsigned short V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector unsigned short));
 }
 
 static inline __ATTRS_o_ai void
 vec_xst(__vector signed int __vec, long __offset, signed int *__ptr) {
-  *(__vector signed int *)((char *)__ptr + __offset) = __vec;
+  __vector signed int V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V, sizeof(__vector signed int));
 }
 
 static inline __ATTRS_o_ai void
 vec_xst(__vector unsigned int __vec, long __offset, unsigned int *__ptr) {
-  *(__vector unsigned int *)((char *)__ptr + __offset) = __vec;
+  __vector unsigned int V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector unsigned int));
 }
 
 static inline __ATTRS_o_ai void
 vec_xst(__vector signed long long __vec, long __offset,
-          signed long long *__ptr) {
-  *(__vector signed long long *)((char *)__ptr + __offset) = __vec;
+        signed long long *__ptr) {
+  __vector signed long long V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector signed long long));
 }
 
 static inline __ATTRS_o_ai void
 vec_xst(__vector unsigned long long __vec, long __offset,
-          unsigned long long *__ptr) {
-  *(__vector unsigned long long *)((char *)__ptr + __offset) = __vec;
+        unsigned long long *__ptr) {
+  __vector unsigned long long V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector unsigned long long));
 }
 
 #if __ARCH__ >= 12
 static inline __ATTRS_o_ai void
 vec_xst(__vector float __vec, long __offset, float *__ptr) {
-  *(__vector float *)((char *)__ptr + __offset) = __vec;
+  __vector float V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V, sizeof(__vector float));
 }
 #endif
 
 static inline __ATTRS_o_ai void
 vec_xst(__vector double __vec, long __offset, double *__ptr) {
-  *(__vector double *)((char *)__ptr + __offset) = __vec;
+  __vector double V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V, sizeof(__vector double));
 }
 
 /*-- vec_xstd2 --------------------------------------------------------------*/
@@ -1246,57 +1313,73 @@ vec_xst(__vector double __vec, long __offset, double *__ptr) {
 // This prototype is deprecated.
 static inline __ATTRS_o_ai void
 vec_xstd2(__vector signed char __vec, long __offset, signed char *__ptr) {
-  *(__vector signed char *)((char *)__ptr + __offset) = __vec;
+  __vector signed char V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector signed char));
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai void
 vec_xstd2(__vector unsigned char __vec, long __offset, unsigned char *__ptr) {
-  *(__vector unsigned char *)((char *)__ptr + __offset) = __vec;
+  __vector unsigned char V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector unsigned char));
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai void
 vec_xstd2(__vector signed short __vec, long __offset, signed short *__ptr) {
-  *(__vector signed short *)((char *)__ptr + __offset) = __vec;
+  __vector signed short V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector signed short));
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai void
 vec_xstd2(__vector unsigned short __vec, long __offset, unsigned short *__ptr) {
-  *(__vector unsigned short *)((char *)__ptr + __offset) = __vec;
+  __vector unsigned short V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector unsigned short));
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai void
 vec_xstd2(__vector signed int __vec, long __offset, signed int *__ptr) {
-  *(__vector signed int *)((char *)__ptr + __offset) = __vec;
+  __vector signed int V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V, sizeof(__vector signed int));
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai void
 vec_xstd2(__vector unsigned int __vec, long __offset, unsigned int *__ptr) {
-  *(__vector unsigned int *)((char *)__ptr + __offset) = __vec;
+  __vector unsigned int V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector unsigned int));
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai void
 vec_xstd2(__vector signed long long __vec, long __offset,
           signed long long *__ptr) {
-  *(__vector signed long long *)((char *)__ptr + __offset) = __vec;
+  __vector signed long long V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector signed long long));
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai void
 vec_xstd2(__vector unsigned long long __vec, long __offset,
           unsigned long long *__ptr) {
-  *(__vector unsigned long long *)((char *)__ptr + __offset) = __vec;
+  __vector unsigned long long V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector unsigned long long));
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai void
 vec_xstd2(__vector double __vec, long __offset, double *__ptr) {
-  *(__vector double *)((char *)__ptr + __offset) = __vec;
+  __vector double V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V, sizeof(__vector double));
 }
 
 /*-- vec_xstw4 --------------------------------------------------------------*/
@@ -1304,37 +1387,48 @@ vec_xstd2(__vector double __vec, long __offset, double *__ptr) {
 // This prototype is deprecated.
 static inline __ATTRS_o_ai void
 vec_xstw4(__vector signed char __vec, long __offset, signed char *__ptr) {
-  *(__vector signed char *)((char *)__ptr + __offset) = __vec;
+  __vector signed char V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector signed char));
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai void
 vec_xstw4(__vector unsigned char __vec, long __offset, unsigned char *__ptr) {
-  *(__vector unsigned char *)((char *)__ptr + __offset) = __vec;
+  __vector unsigned char V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector unsigned char));
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai void
 vec_xstw4(__vector signed short __vec, long __offset, signed short *__ptr) {
-  *(__vector signed short *)((char *)__ptr + __offset) = __vec;
+  __vector signed short V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector signed short));
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai void
 vec_xstw4(__vector unsigned short __vec, long __offset, unsigned short *__ptr) {
-  *(__vector unsigned short *)((char *)__ptr + __offset) = __vec;
+  __vector unsigned short V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector unsigned short));
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai void
 vec_xstw4(__vector signed int __vec, long __offset, signed int *__ptr) {
-  *(__vector signed int *)((char *)__ptr + __offset) = __vec;
+  __vector signed int V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V, sizeof(__vector signed int));
 }
 
 // This prototype is deprecated.
 static inline __ATTRS_o_ai void
 vec_xstw4(__vector unsigned int __vec, long __offset, unsigned int *__ptr) {
-  *(__vector unsigned int *)((char *)__ptr + __offset) = __vec;
+  __vector unsigned int V = __vec;
+  __builtin_memcpy(((char *)__ptr + __offset), &V,
+                   sizeof(__vector unsigned int));
 }
 
 /*-- vec_load_bndry ---------------------------------------------------------*/

diff  --git a/clang/test/CodeGen/SystemZ/builtins-systemz-zvector-constrained.c b/clang/test/CodeGen/SystemZ/builtins-systemz-zvector-constrained.c
index 7fd64ed82b15..596d50211689 100644
--- a/clang/test/CodeGen/SystemZ/builtins-systemz-zvector-constrained.c
+++ b/clang/test/CodeGen/SystemZ/builtins-systemz-zvector-constrained.c
@@ -66,16 +66,28 @@ void test_core(void) {
   // CHECK-ASM: vsceg %{{.*}}, 0(%{{.*}},%{{.*}}), 1
 
   vd = vec_xl(idx, cptrd);
-  // CHECK-ASM: vl
+  // CHECK-ASM-NEXT: lgfrl   %r3, idx
+  // CHECK-ASM-NEXT: lgrl    %r4, cptrd
+  // CHECK-ASM-NEXT: vl      %v0, 0(%r3,%r4){{$}}
+  // CHECK-ASM-NEXT: vst
 
   vd = vec_xld2(idx, cptrd);
-  // CHECK-ASM: vl
+  // CHECK-ASM-NEXT: lgfrl   %r3, idx
+  // CHECK-ASM-NEXT: lgrl    %r4, cptrd
+  // CHECK-ASM-NEXT: vl      %v0, 0(%r3,%r4){{$}}
+  // CHECK-ASM-NEXT: vst
 
   vec_xst(vd, idx, ptrd);
-  // CHECK-ASM: vst
+  // CHECK-ASM-NEXT: vl
+  // CHECK-ASM-NEXT: lgfrl   %r3, idx
+  // CHECK-ASM-NEXT: lgrl    %r4, ptrd
+  // CHECK-ASM-NEXT: vst     %v0, 0(%r3,%r4){{$}}
 
   vec_xstd2(vd, idx, ptrd);
-  // CHECK-ASM: vst
+  // CHECK-ASM-NEXT: vl
+  // CHECK-ASM-NEXT: lgfrl   %r3, idx
+  // CHECK-ASM-NEXT: lgrl    %r4, ptrd
+  // CHECK-ASM-NEXT: vst     %v0, 0(%r3,%r4){{$}}
 
   vd = vec_splat(vd, 0);
   // CHECK: shufflevector <2 x double> %{{.*}}, <2 x double> poison, <2 x i32> zeroinitializer


        


More information about the cfe-commits mailing list