56d343
2016-08-25  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
56d343
56d343
	Backport from mainline (minus test for POWER9 support)
56d343
	2016-08-11  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
56d343
56d343
	PR target/72863
56d343
	* vsx.md (vsx_load_<mode>): For P8LE, emit swaps at expand time.
56d343
	(vsx_store_<mode>): Likewise.
56d343
56d343
	* gcc.target/powerpc/pr72863.c: New test.
56d343
56d343
--- gcc/config/rs6000/vsx.md	(revision 239761)
56d343
+++ gcc/config/rs6000/vsx.md	(revision 239762)
56d343
@@ -716,13 +716,27 @@ (define_expand "vsx_load_<mode>"
56d343
   [(set (match_operand:VSX_M 0 "vsx_register_operand" "")
56d343
 	(match_operand:VSX_M 1 "memory_operand" ""))]
56d343
   "VECTOR_MEM_VSX_P (<MODE>mode)"
56d343
-  "")
56d343
+{
56d343
+  /* Expand to swaps if needed, prior to swap optimization.  */
56d343
+  if (!BYTES_BIG_ENDIAN)
56d343
+    {
56d343
+      rs6000_emit_le_vsx_move (operands[0], operands[1], <MODE>mode);
56d343
+      DONE;
56d343
+    }
56d343
+})
56d343
 
56d343
 (define_expand "vsx_store_<mode>"
56d343
   [(set (match_operand:VSX_M 0 "memory_operand" "")
56d343
 	(match_operand:VSX_M 1 "vsx_register_operand" ""))]
56d343
   "VECTOR_MEM_VSX_P (<MODE>mode)"
56d343
-  "")
56d343
+{
56d343
+  /* Expand to swaps if needed, prior to swap optimization.  */
56d343
+  if (!BYTES_BIG_ENDIAN)
56d343
+    {
56d343
+      rs6000_emit_le_vsx_move (operands[0], operands[1], <MODE>mode);
56d343
+      DONE;
56d343
+    }
56d343
+})
56d343
 
56d343
 
56d343
 ;; VSX vector floating point arithmetic instructions.  The VSX scalar
56d343
--- gcc/testsuite/gcc.target/powerpc/pr72863.c	(nonexistent)
56d343
+++ gcc/testsuite/gcc.target/powerpc/pr72863.c	(revision 239762)
56d343
@@ -0,0 +1,27 @@
56d343
+/* { dg-do compile { target { powerpc64le-*-* } } } */
56d343
+/* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power8" } } */
56d343
+/* { dg-options "-mcpu=power8 -O3" } */
56d343
+/* { dg-final { scan-assembler "lxvd2x" } } */
56d343
+/* { dg-final { scan-assembler "stxvd2x" } } */
56d343
+/* { dg-final { scan-assembler-not "xxpermdi" } } */
56d343
+
56d343
+#include <altivec.h>
56d343
+
56d343
+extern unsigned char *src, *dst;
56d343
+
56d343
+void b(void)
56d343
+{
56d343
+  int i;
56d343
+
56d343
+  unsigned char *s8 = src;
56d343
+  unsigned char *d8 = dst;
56d343
+
56d343
+  for (i = 0; i < 100; i++) {
56d343
+    vector unsigned char vs = vec_vsx_ld(0, s8);
56d343
+    vector unsigned char vd = vec_vsx_ld(0, d8);
56d343
+    vector unsigned char vr = vec_xor(vs, vd);
56d343
+    vec_vsx_st(vr, 0, d8);
56d343
+    s8 += 16;
56d343
+    d8 += 16;
56d343
+  }
56d343
+}