From 01718e96e798e62564e8aa3e4496e78441811c71 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Tue, 21 Feb 2012 12:37:33 +0000 Subject: [PATCH] re PR tree-optimization/52324 (Store motion no longer performed) 2012-02-21 Richard Guenther PR tree-optimization/52324 * gimplify.c (gimplify_expr): When re-gimplifying expressions do not gimplify a MEM_REF address operand if it is already in suitable form. * gcc.dg/tree-ssa/ssa-lim-10.c: New testcase. From-SVN: r184435 --- gcc/ChangeLog | 7 +++++ gcc/gimplify.c | 18 +++++++++---- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-10.c | 31 ++++++++++++++++++++++ 4 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-10.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 87dac5390ff..4388b686717 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2012-02-21 Richard Guenther + + PR tree-optimization/52324 + * gimplify.c (gimplify_expr): When re-gimplifying expressions + do not gimplify a MEM_REF address operand if it is already + in suitable form. + 2012-02-21 Andreas Krebbel * config/s390/s390.md ("fixuns_truncsi2"): Replace diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 782adc34caf..a214134c554 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -7061,15 +7061,23 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, ret = GS_OK; break; } - ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, - is_gimple_mem_ref_addr, fb_rvalue); - if (ret == GS_ERROR) - break; + /* Avoid re-gimplifying the address operand if it is already + in suitable form. Re-gimplifying would mark the address + operand addressable. Always gimplify when not in SSA form + as we still may have to gimplify decls with value-exprs. */ + if (!gimplify_ctxp || !gimplify_ctxp->into_ssa + || !is_gimple_mem_ref_addr (TREE_OPERAND (*expr_p, 0))) + { + ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, + is_gimple_mem_ref_addr, fb_rvalue); + if (ret == GS_ERROR) + break; + } recalculate_side_effects (*expr_p); ret = GS_ALL_DONE; break; - /* Constants need not be gimplified. */ + /* Constants need not be gimplified. */ case INTEGER_CST: case REAL_CST: case FIXED_CST: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0fe2f699e57..5592364dd6e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-02-21 Richard Guenther + + PR tree-optimization/52324 + * gcc.dg/tree-ssa/ssa-lim-10.c: New testcase. + 2012-02-21 Georg-Johann Lay PR middle-end/51782 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-10.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-10.c new file mode 100644 index 00000000000..bc149265dd7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-10.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-lim1-details" } */ + +int *l, *r; +int test_func(void) +{ + int i; + int direction; + static int pos; + + pos = 0; + direction = 1; + + for ( i = 0; i <= 400; i++ ) + { + if ( direction == 0 ) + pos = l[pos]; + else + pos = r[pos]; + + if ( pos == -1 ) + { + pos = 0; + direction = !direction; + } + } + return i; +} + +/* { dg-final { scan-tree-dump "Executing store motion of pos" "lim1" } } */ +/* { dg-final { cleanup-tree-dump "lim1" } } */ -- 2.30.2