public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] Fix tree-optimization/50414
@ 2011-09-18 16:10 Ira Rosen
  0 siblings, 0 replies; only message in thread
From: Ira Rosen @ 2011-09-18 16:10 UTC (permalink / raw)
  To: gcc-patches; +Cc: Patch Tracking

Hi,

This patch adds a missing handling of MAX/MIN_EXPR in SLP reduction.

Boostrapped and tested on powerpc64-suse-linux.
Committed to trunk.

Ira

ChangeLog:

        PR tree-optimization/50414
        * tree-vect-slp.c (vect_get_constant_vectors): Handle MAX_EXPR and
        MIN_EXPR.

testsuite/ChangeLog:

        PR tree-optimization/50414
        * gfortran.dg/vect/Ofast-pr50414.f90: New.
        * gfortran.dg/vect/vect.exp: Run Ofast-* tests with -Ofast.
        * gcc.dg/vect/no-scevccp-noreassoc-slp-reduc-7.c: New.


Index: tree-vect-slp.c
===================================================================
--- tree-vect-slp.c     (revision 178939)
+++ tree-vect-slp.c     (working copy)
@@ -1902,6 +1902,8 @@ vect_get_constant_vectors (tree op, slp_tree slp_n
   bool constant_p, is_store;
   tree neutral_op = NULL;
   enum tree_code code = gimple_assign_rhs_code (stmt);
+  gimple def_stmt;
+  struct loop *loop;

   if (STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_reduction_def)
     {
@@ -1943,8 +1945,16 @@ vect_get_constant_vectors (tree op, slp_tree slp_n
             neutral_op = build_int_cst (TREE_TYPE (op), -1);
             break;

+          case MAX_EXPR:
+          case MIN_EXPR:
+            def_stmt = SSA_NAME_DEF_STMT (op);
+            loop = (gimple_bb (stmt))->loop_father;
+            neutral_op = PHI_ARG_DEF_FROM_EDGE (def_stmt,
+                                                loop_preheader_edge (loop));
+            break;
+
           default:
-             neutral_op = NULL;
+            neutral_op = NULL;
         }
     }

@@ -1997,8 +2007,8 @@ vect_get_constant_vectors (tree op, slp_tree slp_n

           if (reduc_index != -1)
             {
-              struct loop *loop = (gimple_bb (stmt))->loop_father;
-              gimple def_stmt = SSA_NAME_DEF_STMT (op);
+              loop = (gimple_bb (stmt))->loop_father;
+              def_stmt = SSA_NAME_DEF_STMT (op);

               gcc_assert (loop);
Index: testsuite/gfortran.dg/vect/Ofast-pr50414.f90
===================================================================
--- testsuite/gfortran.dg/vect/Ofast-pr50414.f90        (revision 0)
+++ testsuite/gfortran.dg/vect/Ofast-pr50414.f90        (revision 0)
@@ -0,0 +1,11 @@
+! { dg-do compile }
+
+      SUBROUTINE  SUB  (A,L,YMAX)
+      DIMENSION A(L)
+      YMA=A(1)
+      DO 2 I=1,L,2
+    2 YMA=MAX(YMA,A(I),A(I+1))
+      CALL PROUND(YMA)
+      END
+
+! { dg-final { cleanup-tree-dump "vect" } }
Index: testsuite/gfortran.dg/vect/vect.exp
===================================================================
--- testsuite/gfortran.dg/vect/vect.exp (revision 178939)
+++ testsuite/gfortran.dg/vect/vect.exp (working copy)
@@ -84,6 +84,12 @@ lappend DEFAULT_VECTCFLAGS "-O3"
 dg-runtest [lsort [glob -nocomplain
$srcdir/$subdir/O3-*.\[fF\]{,90,95,03,08} ]]  \
         "" $DEFAULT_VECTCFLAGS

+# With -Ofast
+set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS
+lappend DEFAULT_VECTCFLAGS "-Ofast"
+dg-runtest [lsort [glob -nocomplain
$srcdir/$subdir/Ofast-*.\[fF\]{,90,95,03,08} ]]  \
+        "" $DEFAULT_VECTCFLAGS
+
 # Clean up.
 set dg-do-what-default ${save-dg-do-what-default}

Index: testsuite/gcc.dg/vect/no-scevccp-noreassoc-slp-reduc-7.c
===================================================================
--- testsuite/gcc.dg/vect/no-scevccp-noreassoc-slp-reduc-7.c    (revision 0)
+++ testsuite/gcc.dg/vect/no-scevccp-noreassoc-slp-reduc-7.c    (revision 0)
@@ -0,0 +1,42 @@
+/* { dg-require-effective-target vect_int } */
+
+#include <stdarg.h>
+#include "tree-vect.h"
+
+#define N 16
+#define MAX 121
+
+unsigned int ub[N] = {0,3,6,9,12,15,18,121,24,27,113,33,36,39,42,45};
+
+/* Vectorization of reduction using loop-aware SLP (with unrolling).  */
+
+__attribute__ ((noinline))
+int main1 (int n)
+{
+  int i;
+  unsigned int max = 50;
+
+  for (i = 0; i < n; i++) {
+    max = max < ub[2*i] ? ub[2*i] : max;
+    max = max < ub[2*i + 1] ? ub[2*i + 1] : max;
+  }
+
+  /* Check results:  */
+  if (max != MAX)
+    abort ();
+
+  return 0;
+}
+
+int main (void)
+{
+  check_vect ();
+
+  main1 (N/2);
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" {
xfail vect_no_int_max } } } */
+/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 1
"vect" { xfail vect_no_int_max } } } */
+/* { dg-final { cleanup-tree-dump "vect" } } */
+

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-09-18 11:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-18 16:10 [patch] Fix tree-optimization/50414 Ira Rosen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).