diff options
author | dorit <dorit@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-08-03 20:35:05 +0000 |
---|---|---|
committer | dorit <dorit@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-08-03 20:35:05 +0000 |
commit | 9896f25bbd2ccf9ac0d487e0fdbdf048386d28c7 (patch) | |
tree | 5600c4515b0df41a7300352395b0f3c145a96196 | |
parent | f03c0a41f8c4ff72fae7b0e8485a35e241cb06bb (diff) | |
download | gcc-9896f25bbd2ccf9ac0d487e0fdbdf048386d28c7.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@115910 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 16 | ||||
-rw-r--r-- | gcc/cgraphunit.c | 47 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 11 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/no-section-anchors-vect-69.c (renamed from gcc/testsuite/gcc.dg/vect/vect-69.c) | 0 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/section-anchors-pr27770.c | 31 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/section-anchors-vect-69.c | 119 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/vect.exp | 12 | ||||
-rw-r--r-- | gcc/testsuite/lib/target-supports.exp | 18 | ||||
-rw-r--r-- | gcc/tree-flow.h | 2 | ||||
-rw-r--r-- | gcc/tree-vect-analyze.c | 5 | ||||
-rw-r--r-- | gcc/tree-vectorizer.c | 4 |
11 files changed, 263 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index aa7b5441cf1..baafabfdc64 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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 diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index 256850224db..ddaecd3aa1c 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 1f740fbb4e1..a2256d5d2cf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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/vect-69.c b/gcc/testsuite/gcc.dg/vect/no-section-anchors-vect-69.c index 6da9bfbfdcc..6da9bfbfdcc 100644 --- a/gcc/testsuite/gcc.dg/vect/vect-69.c +++ b/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 00000000000..7513d93a43d --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/section-anchors-pr27770.c @@ -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 index 00000000000..f33a37df027 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/section-anchors-vect-69.c @@ -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.exp b/gcc/testsuite/gcc.dg/vect/vect.exp index 2873b5860ee..007aa203f7d 100644 --- a/gcc/testsuite/gcc.dg/vect/vect.exp +++ b/gcc/testsuite/gcc.dg/vect/vect.exp @@ -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\]]] \ diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index 57cfa7fdde8..bf8f7e796bb 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -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 { } { diff --git a/gcc/tree-flow.h b/gcc/tree-flow.h index eee6fa434b0..d0c81515a26 100644 --- a/gcc/tree-flow.h +++ b/gcc/tree-flow.h @@ -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); diff --git a/gcc/tree-vect-analyze.c b/gcc/tree-vect-analyze.c index b031ceb1640..9df8ba26606 100644 --- a/gcc/tree-vect-analyze.c +++ b/gcc/tree-vect-analyze.c @@ -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)) { diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c index c0d783474de..bfdac3bdfbb 100644 --- a/gcc/tree-vectorizer.c +++ b/gcc/tree-vectorizer.c @@ -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; } |