From 0be79f24f8534db6eac81a35a94260d6a6f13eea Mon Sep 17 00:00:00 2001 From: Dorit Nuzman Date: Thu, 3 Aug 2006 20:35:05 +0000 Subject: [PATCH] re PR middle-end/27770 (wrong code in spec tests for -ftree-vectorize -maltivec) 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 --- gcc/ChangeLog | 16 +++ gcc/cgraphunit.c | 47 +++++++ gcc/testsuite/ChangeLog | 11 ++ ...vect-69.c => no-section-anchors-vect-69.c} | 0 .../gcc.dg/vect/section-anchors-pr27770.c | 31 +++++ .../gcc.dg/vect/section-anchors-vect-69.c | 119 ++++++++++++++++++ gcc/testsuite/gcc.dg/vect/vect.exp | 12 ++ gcc/testsuite/lib/target-supports.exp | 18 +++ gcc/tree-flow.h | 2 + gcc/tree-vect-analyze.c | 5 +- gcc/tree-vectorizer.c | 4 +- 11 files changed, 263 insertions(+), 2 deletions(-) rename gcc/testsuite/gcc.dg/vect/{vect-69.c => no-section-anchors-vect-69.c} (100%) create mode 100644 gcc/testsuite/gcc.dg/vect/section-anchors-pr27770.c create mode 100644 gcc/testsuite/gcc.dg/vect/section-anchors-vect-69.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index aa7b5441cf19..baafabfdc640 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2006-08-03 Dorit Nuzman + + 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 PR target/27566 diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index 256850224dbf..ddaecd3aa1c6 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -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. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1f740fbb4e13..a2256d5d2cf5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,14 @@ +2006-08-03 Dorit Nuzman + + 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 * gcc.dg/20060801-1.c: Add missing '}'. diff --git a/gcc/testsuite/gcc.dg/vect/vect-69.c b/gcc/testsuite/gcc.dg/vect/no-section-anchors-vect-69.c similarity index 100% rename from gcc/testsuite/gcc.dg/vect/vect-69.c rename to gcc/testsuite/gcc.dg/vect/no-section-anchors-vect-69.c 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 index 000000000000..7513d93a43db --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/section-anchors-pr27770.c @@ -0,0 +1,31 @@ +/* { dg-require-effective-target section_anchors } */ + +#include +#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 index 000000000000..f33a37df027b --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/section-anchors-vect-69.c @@ -0,0 +1,119 @@ +/* { dg-require-effective-target section_anchors } */ + +#include +#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 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; }