re PR middle-end/27770 (wrong code in spec tests for -ftree-vectorize -maltivec)
authorDorit Nuzman <dorit@il.ibm.com>
Thu, 3 Aug 2006 20:35:05 +0000 (20:35 +0000)
committerDorit Nuzman <dorit@gcc.gnu.org>
Thu, 3 Aug 2006 20:35:05 +0000 (20:35 +0000)
        PR tree-optimization/27770
        * tree-vectorizer.h (get_vectype_for_scalar_type): Function
        declaration removed (moved to tree-flow.h).
        (vect_can_force_dr_alignment_p): Likewise.
        * tree-flow.h (get_vectype_for_scalar_type): New function declaration
        (moved from tree-vectorizer.h).
        (vect_can_force_dr_alignment_p): Likewise.
        * tree-vectorizer.c (vect_print_dump_info): Allow calling this function
        from outside the vectorizer - in particular from cgraph stage.
        * tree-vect-analyze.c (vect_compute_data_ref_alignment): Don't increase
        the alignment of global arrays when -fsection-anchors is enabled.
        * cgraphunit.c (cgraph_increase_alignment): New function.
        (cgraph_optimize): Call cgraph_increase_alignment.

From-SVN: r115910

12 files changed:
gcc/ChangeLog
gcc/cgraphunit.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/no-section-anchors-vect-69.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/section-anchors-pr27770.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/section-anchors-vect-69.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-69.c [deleted file]
gcc/testsuite/gcc.dg/vect/vect.exp
gcc/testsuite/lib/target-supports.exp
gcc/tree-flow.h
gcc/tree-vect-analyze.c
gcc/tree-vectorizer.c

index aa7b5441cf19a714cfb92242333e290e60ef77dc..baafabfdc6403f063f0ff0387aace761ef03b259 100644 (file)
@@ -1,3 +1,19 @@
+2006-08-03  Dorit Nuzman  <dorit@il.ibm.com>
+
+        PR tree-optimization/27770
+        * tree-vectorizer.h (get_vectype_for_scalar_type): Function
+        declaration removed (moved to tree-flow.h).
+        (vect_can_force_dr_alignment_p): Likewise.
+        * tree-flow.h (get_vectype_for_scalar_type): New function declaration
+        (moved from tree-vectorizer.h).
+        (vect_can_force_dr_alignment_p): Likewise.
+        * tree-vectorizer.c (vect_print_dump_info): Allow calling this function
+        from outside the vectorizer - in particular from cgraph stage.
+        * tree-vect-analyze.c (vect_compute_data_ref_alignment): Don't increase
+        the alignment of global arrays when -fsection-anchors is enabled.
+        * cgraphunit.c (cgraph_increase_alignment): New function.
+        (cgraph_optimize): Call cgraph_increase_alignment.
+
 2006-08-03  David Edelsohn  <edelsohn@gnu.org>
 
        PR target/27566
index 256850224dbf1f90bc7564dcb77cc84680f4c725..ddaecd3aa1c6a579f6770d327fc9cf52afcaac2d 100644 (file)
@@ -172,6 +172,7 @@ static void cgraph_mark_functions_to_output (void);
 static void cgraph_expand_function (struct cgraph_node *);
 static tree record_reference (tree *, int *, void *);
 static void cgraph_output_pending_asms (void);
+static void cgraph_increase_alignment (void);
 
 /* Records tree nodes seen in record_reference.  Simply using
    walk_tree_without_duplicates doesn't guarantee each node is visited
@@ -1506,6 +1507,7 @@ cgraph_optimize (void)
   /* This pass remove bodies of extern inline functions we never inlined.
      Do this later so other IPA passes see what is really going on.  */
   cgraph_remove_unreachable_nodes (false, dump_file);
+  cgraph_increase_alignment ();
   cgraph_global_info_ready = true;
   if (cgraph_dump_file)
     {
@@ -1565,6 +1567,51 @@ cgraph_optimize (void)
 #endif
 }
 
+/* Increase alignment of global arrays to improve vectorization potential.
+   TODO:
+   - Consider also structs that have an array field.
+   - Use ipa analysis to prune arrays that can't be vectorized?
+     This should involve global alignment analysis and in the future also
+     array padding.  */
+
+static void
+cgraph_increase_alignment (void)
+{
+  if (flag_section_anchors && flag_tree_vectorize)
+    {
+      struct cgraph_varpool_node *vnode;
+
+      /* Increase the alignment of all global arrays for vectorization.  */
+      for (vnode = cgraph_varpool_nodes_queue;
+           vnode;
+           vnode = vnode->next_needed)
+        {
+          tree vectype, decl = vnode->decl;
+          unsigned int alignment;
+
+          if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
+            continue;
+          vectype = get_vectype_for_scalar_type (TREE_TYPE (TREE_TYPE (decl)));
+          if (!vectype)
+            continue;
+          alignment = TYPE_ALIGN (vectype);
+          if (DECL_ALIGN (decl) >= alignment)
+            continue;
+
+          if (vect_can_force_dr_alignment_p (decl, alignment))
+            { 
+              DECL_ALIGN (decl) = TYPE_ALIGN (vectype);
+              DECL_USER_ALIGN (decl) = 1;
+              if (cgraph_dump_file)
+                { 
+                  fprintf (cgraph_dump_file, "Increasing alignment of decl: ");
+                  print_generic_expr (cgraph_dump_file, decl, TDF_SLIM);
+                }
+            }
+        }
+    }
+}
+
 /* Generate and emit a static constructor or destructor.  WHICH must be
    one of 'I' or 'D'.  BODY should be a STATEMENT_LIST containing
    GENERIC statements.  */
index 1f740fbb4e1397ec6c80a7fd6dfa2200bcd7efe5..a2256d5d2cf5e1ad59a61f3733977c37e0ecc33d 100644 (file)
@@ -1,3 +1,14 @@
+2006-08-03  Dorit Nuzman  <dorit@il.ibm.com>
+
+       PR tree-optimization/27770
+       * lib/target-support.exp: New target keyword "section_anchors". 
+       * gcc.dg/vect/vect.exp: Add -fsection-anchors to compilation of some
+       tests.
+       * gcc.dg/vect/section-anchors-pr27770.c: New test.
+       * gcc.dg/vect/vect-69.c: Removed. Replaced by:
+       * gcc.dg/vect/section-anchors-vect-69.c: New test.
+       * gcc.dg/vect/no-section-anchors-vect-69.c: New test.
+       
 2006-08-03  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>
 
        * gcc.dg/20060801-1.c: Add missing '}'.
diff --git a/gcc/testsuite/gcc.dg/vect/no-section-anchors-vect-69.c b/gcc/testsuite/gcc.dg/vect/no-section-anchors-vect-69.c
new file mode 100644 (file)
index 0000000..6da9bfb
--- /dev/null
@@ -0,0 +1,117 @@
+/* { dg-require-effective-target vect_int } */
+
+#include <stdarg.h>
+#include "tree-vect.h"
+
+#define N 32
+
+struct s{
+  int m;
+  int n[N][N][N];
+};
+
+struct s2{
+  int m;
+  int n[N-1][N-1][N-1];
+};
+
+struct test1{
+  struct s a; /* array a.n is unaligned */
+  int b;
+  int c;
+  struct s e; /* array e.n is aligned */
+};
+
+struct test2{
+  struct s2 a; /* array a.n is unaligned */
+  int b;
+  int c;
+  struct s2 e; /* array e.n is aligned */
+};
+
+
+struct test1 tmp1[4];
+struct test2 tmp2[4];
+
+int main1 ()
+{  
+  int i,j;
+
+  /* 1. unaligned */
+  for (i = 0; i < N; i++)
+    {
+      tmp1[2].a.n[1][2][i] = 5;
+    }
+
+  /* check results:  */
+  for (i = 0; i <N; i++)
+    {
+      if (tmp1[2].a.n[1][2][i] != 5)
+        abort ();
+    }
+
+  /* 2. aligned */
+  for (i = 3; i < N-1; i++)
+    {
+      tmp1[2].a.n[1][2][i] = 6;
+    }
+
+  /* check results:  */
+  for (i = 3; i < N-1; i++)
+    {
+      if (tmp1[2].a.n[1][2][i] != 6)
+        abort ();
+    }
+
+  /* 3. aligned */
+  for (i = 0; i < N; i++)
+    {
+      for (j = 0; j < N; j++)
+       {
+          tmp1[2].e.n[1][i][j] = 8;
+       }
+    }
+
+  /* check results:  */
+  for (i = 0; i < N; i++)
+    {
+      for (j = 0; j < N; j++)
+       {
+          if (tmp1[2].e.n[1][i][j] != 8)
+           abort ();
+       }
+    }
+
+  /* 4. unaligned */
+  for (i = 0; i < N-4; i++)
+    {
+      for (j = 0; j < N-4; j++)
+       {
+          tmp2[2].e.n[1][i][j] = 8;
+       }
+    }
+
+  /* check results:  */
+  for (i = 0; i < N-4; i++)
+    {
+      for (j = 0; j < N-4; j++)
+       {
+          if (tmp2[2].e.n[1][i][j] != 8)
+           abort ();
+       }
+    }
+
+  return 0;
+}
+
+int main (void)
+{ 
+  check_vect ();
+  
+  return main1 ();
+} 
+
+/* { dg-final { scan-tree-dump-times "vectorized 4 loops" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Vectorizing an unaligned access" 0 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Alignment of access forced using peeling" 2 "vect" } } */
+/* { dg-final { cleanup-tree-dump "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/section-anchors-pr27770.c b/gcc/testsuite/gcc.dg/vect/section-anchors-pr27770.c
new file mode 100644 (file)
index 0000000..7513d93
--- /dev/null
@@ -0,0 +1,31 @@
+/* { dg-require-effective-target section_anchors } */ 
+
+#include <stdarg.h>
+#include "tree-vect.h"
+
+short x;
+static short f[100] = {0};
+int
+bar (void)
+{
+  return f[0];
+}
+void
+foo (void)
+{
+  int i;
+  for (i = 0; i < 100; i++)
+    f[i]++;
+}
+int main (void)
+{
+  int i;
+  check_vect ();
+  foo ();
+  for (i = 0; i < 100; i++)
+    if (f[i]!=1) 
+      abort ();
+  return 0;
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/section-anchors-vect-69.c b/gcc/testsuite/gcc.dg/vect/section-anchors-vect-69.c
new file mode 100644 (file)
index 0000000..f33a37d
--- /dev/null
@@ -0,0 +1,119 @@
+/* { dg-require-effective-target section_anchors } */
+
+#include <stdarg.h>
+#include "tree-vect.h"
+
+#define N 32
+
+struct s{
+  int m;
+  int n[N][N][N];
+};
+
+struct s2{
+  int m;
+  int n[N-1][N-1][N-1];
+};
+
+struct test1{
+  struct s a; /* array a.n is unaligned */
+  int b;
+  int c;
+  struct s e; /* array e.n is aligned */
+};
+
+struct test2{
+  struct s2 a; /* array a.n is unaligned */
+  int b;
+  int c;
+  struct s2 e; /* array e.n is aligned */
+};
+
+
+struct test1 tmp1[4];
+struct test2 tmp2[4];
+
+int main1 ()
+{  
+  int i,j;
+
+  /* 1. unaligned */
+  for (i = 0; i < N; i++)
+    {
+      tmp1[2].a.n[1][2][i] = 5;
+    }
+
+  /* check results:  */
+  for (i = 0; i <N; i++)
+    {
+      if (tmp1[2].a.n[1][2][i] != 5)
+        abort ();
+    }
+
+  /* 2. aligned */
+  for (i = 3; i < N-1; i++)
+    {
+      tmp1[2].a.n[1][2][i] = 6;
+    }
+
+  /* check results:  */
+  for (i = 3; i < N-1; i++)
+    {
+      if (tmp1[2].a.n[1][2][i] != 6)
+        abort ();
+    }
+
+  /* 3. aligned */
+  for (i = 0; i < N; i++)
+    {
+      for (j = 0; j < N; j++)
+       {
+          tmp1[2].e.n[1][i][j] = 8;
+       }
+    }
+
+  /* check results:  */
+  for (i = 0; i < N; i++)
+    {
+      for (j = 0; j < N; j++)
+       {
+          if (tmp1[2].e.n[1][i][j] != 8)
+           abort ();
+       }
+    }
+
+  /* 4. unaligned */
+  for (i = 0; i < N-4; i++)
+    {
+      for (j = 0; j < N-4; j++)
+       {
+          tmp2[2].e.n[1][i][j] = 8;
+       }
+    }
+
+  /* check results:  */
+  for (i = 0; i < N-4; i++)
+    {
+      for (j = 0; j < N-4; j++)
+       {
+          if (tmp2[2].e.n[1][i][j] != 8)
+           abort ();
+       }
+    }
+
+  return 0;
+}
+
+int main (void)
+{ 
+  check_vect ();
+  
+  return main1 ();
+} 
+
+/* { dg-final { scan-tree-dump-times "vectorized 4 loops" 1 "vect" { target vect_int } } } */
+/* { dg-final { scan-tree-dump-times "Vectorizing an unaligned access" 0 "vect" } } */
+/* Alignment forced using versioning until the pass that increases alignment
+  is extended to handle structs.  */
+/* { dg-final { scan-tree-dump-times "Alignment of access forced using peeling" 4 "vect" { target vect_int } } } */
+/* { dg-final { cleanup-tree-dump "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-69.c b/gcc/testsuite/gcc.dg/vect/vect-69.c
deleted file mode 100644 (file)
index 6da9bfb..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/* { dg-require-effective-target vect_int } */
-
-#include <stdarg.h>
-#include "tree-vect.h"
-
-#define N 32
-
-struct s{
-  int m;
-  int n[N][N][N];
-};
-
-struct s2{
-  int m;
-  int n[N-1][N-1][N-1];
-};
-
-struct test1{
-  struct s a; /* array a.n is unaligned */
-  int b;
-  int c;
-  struct s e; /* array e.n is aligned */
-};
-
-struct test2{
-  struct s2 a; /* array a.n is unaligned */
-  int b;
-  int c;
-  struct s2 e; /* array e.n is aligned */
-};
-
-
-struct test1 tmp1[4];
-struct test2 tmp2[4];
-
-int main1 ()
-{  
-  int i,j;
-
-  /* 1. unaligned */
-  for (i = 0; i < N; i++)
-    {
-      tmp1[2].a.n[1][2][i] = 5;
-    }
-
-  /* check results:  */
-  for (i = 0; i <N; i++)
-    {
-      if (tmp1[2].a.n[1][2][i] != 5)
-        abort ();
-    }
-
-  /* 2. aligned */
-  for (i = 3; i < N-1; i++)
-    {
-      tmp1[2].a.n[1][2][i] = 6;
-    }
-
-  /* check results:  */
-  for (i = 3; i < N-1; i++)
-    {
-      if (tmp1[2].a.n[1][2][i] != 6)
-        abort ();
-    }
-
-  /* 3. aligned */
-  for (i = 0; i < N; i++)
-    {
-      for (j = 0; j < N; j++)
-       {
-          tmp1[2].e.n[1][i][j] = 8;
-       }
-    }
-
-  /* check results:  */
-  for (i = 0; i < N; i++)
-    {
-      for (j = 0; j < N; j++)
-       {
-          if (tmp1[2].e.n[1][i][j] != 8)
-           abort ();
-       }
-    }
-
-  /* 4. unaligned */
-  for (i = 0; i < N-4; i++)
-    {
-      for (j = 0; j < N-4; j++)
-       {
-          tmp2[2].e.n[1][i][j] = 8;
-       }
-    }
-
-  /* check results:  */
-  for (i = 0; i < N-4; i++)
-    {
-      for (j = 0; j < N-4; j++)
-       {
-          if (tmp2[2].e.n[1][i][j] != 8)
-           abort ();
-       }
-    }
-
-  return 0;
-}
-
-int main (void)
-{ 
-  check_vect ();
-  
-  return main1 ();
-} 
-
-/* { dg-final { scan-tree-dump-times "vectorized 4 loops" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Vectorizing an unaligned access" 0 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Alignment of access forced using peeling" 2 "vect" } } */
-/* { dg-final { cleanup-tree-dump "vect" } } */
index 2873b5860ee758ef236866d8d5c0157b27694eda..007aa203f7d576e7670345eaa61a6aa0f21ca075 100644 (file)
@@ -121,6 +121,18 @@ lappend DEFAULT_VECTCFLAGS "-fno-tree-dce"
 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/no-tree-dce-*.\[cS\]]]  \
        "" $DEFAULT_VECTCFLAGS
 
+# -fsection-anchors tests
+set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS
+lappend DEFAULT_VECTCFLAGS "-fsection-anchors"
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/section-anchors-*.\[cS\]]]  \
+       "" $DEFAULT_VECTCFLAGS
+
+# -fno-section-anchors tests
+set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS
+lappend DEFAULT_VECTCFLAGS "-fno-section-anchors"
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/no-section-anchors-*.\[cS\]]]  \
+       "" $DEFAULT_VECTCFLAGS
+
 # With -Os
 lappend DEFAULT_VECTCFLAGS "-Os"
 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/Os-vect-*.\[cS\]]]  \
index 57cfa7fdde8de606d7fe129844795c5ffbc63e56..bf8f7e796bb68b5fc47689cc23ce3baa41230ed4 100644 (file)
@@ -1726,6 +1726,24 @@ proc check_effective_target_vect_int_mult { } {
     return $et_vect_int_mult_saved
 }
 
+# Return 1 if the target supports section-anchors
+
+proc check_effective_target_section_anchors { } {
+    global et_section_anchors_saved
+
+    if [info exists et_section_anchors_saved] {
+        verbose "check_effective_target_section_anchors: using cached result" 2
+    } else {
+        set et_section_anchors_saved 0
+        if { [istarget powerpc*-*-*] } {
+           set et_section_anchors_saved 1
+        }
+    }
+
+    verbose "check_effective_target_section_anchors: returning $et_section_anchors_saved" 2
+    return $et_section_anchors_saved
+}
+
 # Return 1 if the target supports atomic operations on "int" and "long".
 
 proc check_effective_target_sync_int_long { } {
index eee6fa434b015ae49f08df901382292f16f4d85a..d0c81515a26a6845169cb29d116978fd9b98cb11 100644 (file)
@@ -789,6 +789,8 @@ struct tree_niter_desc
 
 /* In tree-vectorizer.c */
 void vectorize_loops (struct loops *);
+extern bool vect_can_force_dr_alignment_p (tree, unsigned int);
+extern tree get_vectype_for_scalar_type (tree);
 
 /* In tree-ssa-phiopt.c */
 bool empty_block_p (basic_block);
index b031ceb16408e19fb9e452104ced934f877a475f..9df8ba26606d7ffbf25eb24a1341f7240cf7df10 100644 (file)
@@ -754,7 +754,10 @@ vect_compute_data_ref_alignment (struct data_reference *dr)
 
   if (!base_aligned) 
     {
-      if (!vect_can_force_dr_alignment_p (base, TYPE_ALIGN (vectype)))
+      /* Do not change the alignment of global variables if 
+        flag_section_anchors is enabled.  */
+      if (!vect_can_force_dr_alignment_p (base, TYPE_ALIGN (vectype))
+         || (TREE_STATIC (base) && flag_section_anchors))
        {
          if (vect_print_dump_info (REPORT_DETAILS))
            {
index c0d783474de152cdfbbc69f97d215ebfe9813264..bfdac3bdfbba63d2dde97c4ab7914bf69c952594 100644 (file)
@@ -1327,6 +1327,9 @@ vect_print_dump_info (enum verbosity_levels vl)
   if (vl > vect_verbosity_level)
     return false;
 
+  if (!current_function_decl || !vect_dump)
+    return false;
+
   if (vect_loop_location == UNKNOWN_LOC)
     fprintf (vect_dump, "\n%s:%d: note: ",
                 DECL_SOURCE_FILE (current_function_decl),
@@ -1335,7 +1338,6 @@ vect_print_dump_info (enum verbosity_levels vl)
     fprintf (vect_dump, "\n%s:%d: note: ", 
             LOC_FILE (vect_loop_location), LOC_LINE (vect_loop_location));
 
-
   return true;
 }