+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
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
/* 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)
{
#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. */
+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 '}'.
--- /dev/null
+/* { 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" } } */
--- /dev/null
+/* { 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" } } */
--- /dev/null
+/* { 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" } } */
+++ /dev/null
-/* { 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" } } */
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\]]] \
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 { } {
/* 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);
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))
{
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),
fprintf (vect_dump, "\n%s:%d: note: ",
LOC_FILE (vect_loop_location), LOC_LINE (vect_loop_location));
-
return true;
}