]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
rs6000.c (v2df_reduction_p): New function.
authorBill Schmidt <wschmidt@linux.vnet.ibm.com>
Tue, 12 Jan 2016 04:49:55 +0000 (04:49 +0000)
committerWilliam Schmidt <wschmidt@gcc.gnu.org>
Tue, 12 Jan 2016 04:49:55 +0000 (04:49 +0000)
[gcc]

2016-01-11  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

* config/rs6000/rs6000.c (v2df_reduction_p): New function.
(rtx_is_swappable_p): Reductions are swappable.
(insn_is_swappable_p): V2DF reductions are swappable.

[gcc/testsuite]

2016-01-11  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

* gcc.target/powerpc/swaps-p8-23.c: New test.
* gcc.target/powerpc/swaps-p8-24.c: Likewise.

From-SVN: r232257

gcc/ChangeLog
gcc/config/rs6000/rs6000.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/powerpc/swaps-p8-23.c [new file with mode: 0644]
gcc/testsuite/gcc.target/powerpc/swaps-p8-24.c [new file with mode: 0644]

index bd84e1f36d635ad2d36d357a063bf93be698589f..4a8a005138f9d587c8bf1c8573dffca992bfda5d 100644 (file)
@@ -1,3 +1,9 @@
+2016-01-11  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
+
+       * config/rs6000/rs6000.c (v2df_reduction_p): New function.
+       (rtx_is_swappable_p): Reductions are swappable.
+       (insn_is_swappable_p): V2DF reductions are swappable.
+
 2016-01-11  John David Anglin  <danglin@gcc.gnu.org>
 
        * config/pa/pa.c (pa_emit_move_sequence): Handle floating point
index cd5243adb0fe73ae716065dd7c6d04acc8da40e6..4cd6a1b58cd8bcc484eeb8508c6b3948df0a6f0a 100644 (file)
@@ -36648,6 +36648,44 @@ const_load_sequence_p (swap_web_entry *insn_entry, rtx insn)
   return true;
 }
 
+/* Return TRUE iff OP matches a V2DF reduction pattern.  See the
+   definition of vsx_reduc_<VEC_reduc_name>_v2df in vsx.md.  */
+static bool
+v2df_reduction_p (rtx op)
+{
+  if (GET_MODE (op) != V2DFmode)
+    return false;
+  
+  enum rtx_code code = GET_CODE (op);
+  if (code != PLUS && code != SMIN && code != SMAX)
+    return false;
+
+  rtx concat = XEXP (op, 0);
+  if (GET_CODE (concat) != VEC_CONCAT)
+    return false;
+
+  rtx select0 = XEXP (concat, 0);
+  rtx select1 = XEXP (concat, 1);
+  if (GET_CODE (select0) != VEC_SELECT || GET_CODE (select1) != VEC_SELECT)
+    return false;
+
+  rtx reg0 = XEXP (select0, 0);
+  rtx reg1 = XEXP (select1, 0);
+  if (!rtx_equal_p (reg0, reg1) || !REG_P (reg0))
+    return false;
+
+  rtx parallel0 = XEXP (select0, 1);
+  rtx parallel1 = XEXP (select1, 1);
+  if (GET_CODE (parallel0) != PARALLEL || GET_CODE (parallel1) != PARALLEL)
+    return false;
+
+  if (!rtx_equal_p (XVECEXP (parallel0, 0, 0), const1_rtx)
+      || !rtx_equal_p (XVECEXP (parallel1, 0, 0), const0_rtx))
+    return false;
+
+  return true;
+}
+
 /* Return 1 iff OP is an operand that will not be affected by having
    vector doublewords swapped in memory.  */
 static unsigned int
@@ -36719,6 +36757,8 @@ rtx_is_swappable_p (rtx op, unsigned int *special)
          *special = SH_XXPERMDI;
          return 1;
        }
+      else if (v2df_reduction_p (op))
+       return 1;
       else
        return 0;
 
@@ -36783,6 +36823,9 @@ rtx_is_swappable_p (rtx op, unsigned int *special)
          case UNSPEC_VSPLT_DIRECT:
            *special = SH_SPLAT;
            return 1;
+         case UNSPEC_REDUC_PLUS:
+         case UNSPEC_REDUC:
+           return 1;
          }
       }
 
@@ -36907,6 +36950,15 @@ insn_is_swappable_p (swap_web_entry *insn_entry, rtx insn,
       return 1;
     }
 
+  /* V2DF reductions are always swappable.  */
+  if (GET_CODE (body) == PARALLEL)
+    {
+      rtx expr = XVECEXP (body, 0, 0);
+      if (GET_CODE (expr) == SET
+         && v2df_reduction_p (SET_SRC (expr)))
+       return 1;
+    }
+
   /* An UNSPEC_VPERM is ok if the mask operand is loaded from the
      constant pool.  */
   if (GET_CODE (body) == SET
index 7e9fc7f2d601e0be3e840800c111469618d711e5..97562b918172a53c58fbcad789d2aa2f4babefe1 100644 (file)
@@ -1,3 +1,8 @@
+2016-01-11  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
+
+       * gcc.target/powerpc/swaps-p8-23.c: New test.
+       * gcc.target/powerpc/swaps-p8-24.c: Likewise.
+
 2016-01-11  John David Anglin  <danglin@gcc.gnu.org>
 
        PR tree-optimization/68356
diff --git a/gcc/testsuite/gcc.target/powerpc/swaps-p8-23.c b/gcc/testsuite/gcc.target/powerpc/swaps-p8-23.c
new file mode 100644 (file)
index 0000000..a3f83ae
--- /dev/null
@@ -0,0 +1,26 @@
+/* { dg-do compile { target { powerpc64le-*-* } } } */
+/* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power8" } } */
+/* { dg-options "-mcpu=power8 -O3 -ffast-math" } */
+/* { dg-final { scan-assembler "lxvd2x" } } */
+/* { dg-final { scan-assembler-not "xxpermdi" } } */
+
+/* Verify that swap optimization works correctly in the presence of
+   a V2DFmode reduction.  */
+
+extern double optvalue;
+extern void obfuscate (double, unsigned int);
+
+void
+foo (double *x, double *y, unsigned int n, unsigned int m)
+{
+  unsigned int i, j;
+  double sacc;
+  for (j = 0; j < m; ++j)
+    {
+      sacc = 0.0;
+      for (i = 0; i < n; ++i)
+       sacc += x[i] * y[i];
+      obfuscate (sacc, n);
+    }
+  optvalue = n * 2.0 * m;
+}
diff --git a/gcc/testsuite/gcc.target/powerpc/swaps-p8-24.c b/gcc/testsuite/gcc.target/powerpc/swaps-p8-24.c
new file mode 100644 (file)
index 0000000..528d6e6
--- /dev/null
@@ -0,0 +1,26 @@
+/* { dg-do compile { target { powerpc64le-*-* } } } */
+/* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power8" } } */
+/* { dg-options "-mcpu=power8 -O3 -ffast-math" } */
+/* { dg-final { scan-assembler "lxvd2x" } } */
+/* { dg-final { scan-assembler-not "xxpermdi" } } */
+
+/* Verify that swap optimization works correctly in the presence of
+   a V4SFmode reduction.  */
+
+extern double optvalue;
+extern void obfuscate (float, unsigned int);
+
+void
+foo (float *x, float *y, unsigned int n, unsigned int m)
+{
+  unsigned int i, j;
+  float sacc;
+  for (j = 0; j < m; ++j)
+    {
+      sacc = 0.0f;
+      for (i = 0; i < n; ++i)
+       sacc += x[i] * y[i];
+      obfuscate (sacc, n);
+    }
+  optvalue = n * 2.0f * m;
+}