diff options
author | Jakub Jelinek <jakub@redhat.com> | 2011-06-14 17:27:24 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2011-06-14 17:27:24 +0200 |
commit | 1ace6185d22d5e23cf3fae342b9b48d18caad644 (patch) | |
tree | a038a08891c77147df8061be5e5979cdc97b4947 /gcc | |
parent | 6b14c6d7ffc25b92aeea21f0c0c050582d3ed771 (diff) | |
download | gcc-1ace6185d22d5e23cf3fae342b9b48d18caad644.zip gcc-1ace6185d22d5e23cf3fae342b9b48d18caad644.tar.gz gcc-1ace6185d22d5e23cf3fae342b9b48d18caad644.tar.bz2 |
re PR fortran/49103 (local variables exchange values / wrong code with -O3)
PR fortran/49103
* tree.h (DECL_NONSHAREABLE): Define.
(struct tree_decl_common): Change decl_common_unused to
decl_nonshareable_flag.
* cfgexpand.c (expand_used_vars_for_block, clear_tree_used):
Ignore vars with DECL_NONSHAREABLE bit set.
* tree-cfg.c (gimple_duplicate_bb): Set DECL_NONSHAREABLE
on stores to automatic aggregate vars.
* gfortran.dg/pr49103.f90: New test.
From-SVN: r175028
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/cfgexpand.c | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/pr49103.f90 | 19 | ||||
-rw-r--r-- | gcc/tree-cfg.c | 19 | ||||
-rw-r--r-- | gcc/tree.h | 9 |
6 files changed, 64 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5a5fc83..2c4b86c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,14 @@ 2011-06-14 Jakub Jelinek <jakub@redhat.com> + PR fortran/49103 + * tree.h (DECL_NONSHAREABLE): Define. + (struct tree_decl_common): Change decl_common_unused to + decl_nonshareable_flag. + * cfgexpand.c (expand_used_vars_for_block, clear_tree_used): + Ignore vars with DECL_NONSHAREABLE bit set. + * tree-cfg.c (gimple_duplicate_bb): Set DECL_NONSHAREABLE + on stores to automatic aggregate vars. + PR rtl-optimization/49390 Revert: 2010-06-29 Bernd Schmidt <bernds@codesourcery.com> diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index b22ba71..491c2fc 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -1098,7 +1098,9 @@ expand_used_vars_for_block (tree block, bool toplevel) /* Expand all variables at this level. */ for (t = BLOCK_VARS (block); t ; t = DECL_CHAIN (t)) - if (TREE_USED (t)) + if (TREE_USED (t) + && ((TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != RESULT_DECL) + || !DECL_NONSHAREABLE (t))) expand_one_var (t, toplevel, true); this_sv_num = stack_vars_num; @@ -1131,6 +1133,8 @@ clear_tree_used (tree block) for (t = BLOCK_VARS (block); t ; t = DECL_CHAIN (t)) /* if (!TREE_STATIC (t) && !DECL_EXTERNAL (t)) */ + if ((TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != RESULT_DECL) + || !DECL_NONSHAREABLE (t)) TREE_USED (t) = 0; for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a61de34..c450a22 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-06-14 Jakub Jelinek <jakub@redhat.com> + + PR fortran/49103 + * gfortran.dg/pr49103.f90: New test. + 2011-06-14 Tom de Vries <tom@codesourcery.com> PR target/45098 diff --git a/gcc/testsuite/gfortran.dg/pr49103.f90 b/gcc/testsuite/gfortran.dg/pr49103.f90 new file mode 100644 index 0000000..e744c9b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr49103.f90 @@ -0,0 +1,19 @@ +! PR fortran/49103 +! { dg-do run } + integer :: a(2), b(2), i, j + open (10, status='scratch') + do j = 1, 2 + a = (/ 0, 0 /) + b = (/ 1, 1 /) + do i = 1, 2 + write (10, *) a + write (10, *) b + end do + end do + rewind (10) + do i = 0, 7 + read (10, *) a + if (any (a .ne. mod (i, 2))) call abort + end do + close (10) +end diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 85fece4..44b5c65 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -5090,6 +5090,7 @@ gimple_duplicate_bb (basic_block bb) { def_operand_p def_p; ssa_op_iter op_iter; + tree lhs; stmt = gsi_stmt (gsi); if (gimple_code (stmt) == GIMPLE_LABEL) @@ -5103,6 +5104,24 @@ gimple_duplicate_bb (basic_block bb) maybe_duplicate_eh_stmt (copy, stmt); gimple_duplicate_stmt_histograms (cfun, copy, cfun, stmt); + /* When copying around a stmt writing into a local non-user + aggregate, make sure it won't share stack slot with other + vars. */ + lhs = gimple_get_lhs (stmt); + if (lhs && TREE_CODE (lhs) != SSA_NAME) + { + tree base = get_base_address (lhs); + if (base + && (TREE_CODE (base) == VAR_DECL + || TREE_CODE (base) == RESULT_DECL) + && DECL_IGNORED_P (base) + && !TREE_STATIC (base) + && !DECL_EXTERNAL (base) + && (TREE_CODE (base) != VAR_DECL + || !DECL_HAS_VALUE_EXPR_P (base))) + DECL_NONSHAREABLE (base) = 1; + } + /* Create new names for all the definitions created by COPY and add replacement mappings for each new name. */ FOR_EACH_SSA_DEF_OPERAND (def_p, copy, op_iter, SSA_OP_ALL_DEFS) @@ -1398,6 +1398,10 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int, #define DECL_READ_P(NODE) \ (TREE_CHECK2 (NODE, VAR_DECL, PARM_DECL)->decl_common.decl_read_flag) +#define DECL_NONSHAREABLE(NODE) \ + (TREE_CHECK2 (NODE, VAR_DECL, \ + RESULT_DECL)->decl_common.decl_nonshareable_flag) + /* In a CALL_EXPR, means that the call is the jump from a thunk to the thunked-to function. */ #define CALL_FROM_THUNK_P(NODE) (CALL_EXPR_CHECK (NODE)->base.protected_flag) @@ -2887,8 +2891,9 @@ struct GTY(()) tree_decl_common { being set. */ unsigned decl_read_flag : 1; - /* Padding so that 'off_align' can be on a 32-bit boundary. */ - unsigned decl_common_unused : 1; + /* In VAR_DECL or RESULT_DECL set when significant code movement precludes + attempting to share the stack slot with some other variable. */ + unsigned decl_nonshareable_flag : 1; /* DECL_OFFSET_ALIGN, used only for FIELD_DECLs. */ unsigned int off_align : 8; |