diff options
| author | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-05-25 09:07:29 +0000 |
|---|---|---|
| committer | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-05-25 09:07:29 +0000 |
| commit | 1a773ec5630df2ad879cd8700a3f2fd0510c1ad0 (patch) | |
| tree | 6502eb3dfad884611a31270c8024502f2d16a26a | |
| parent | 7f8c8ede26368cb7cf9b2dee78d5eb38e2269718 (diff) | |
| download | ppe42-gcc-1a773ec5630df2ad879cd8700a3f2fd0510c1ad0.tar.gz ppe42-gcc-1a773ec5630df2ad879cd8700a3f2fd0510c1ad0.zip | |
2007-05-24 Richard Guenther <rguenther@suse.de>
Andrew Pinski <andrew_pinski@playstation.sony.com>
PR tree-optimization/31982
* tree-ssa-forwprop.c
(forward_propagate_addr_into_variable_array_index): Handle arrays
with element size one.
* gcc.dg/tree-ssa/forwprop-2.c: New testcase.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@125058 138bc75d-0d04-0410-961f-82ee72b054a4
| -rw-r--r-- | gcc/ChangeLog | 7 | ||||
| -rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
| -rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/forwprop-2.c | 22 | ||||
| -rw-r--r-- | gcc/tree-ssa-forwprop.c | 40 |
4 files changed, 56 insertions, 19 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 25eb0013b2b..2342dad7d04 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2007-05-25 Richard Guenther <rguenther@suse.de> + + PR tree-optimization/31982 + * tree-ssa-forwprop.c + (forward_propagate_addr_into_variable_array_index): Handle arrays + with element size one. + 2007-05-24 Andrew Pinski <andrew_pinski@playstation.sony.com> * config/spu/spu.md (smulsi3_highpart): Unshare the rtl chain. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 47f40dff2bf..c0cbf9b3158 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2007-05-25 Richard Guenther <rguenther@suse.de> + Andrew Pinski <andrew_pinski@playstation.sony.com> + + PR tree-optimization/31982 + * gcc.dg/tree-ssa/forwprop-2.c: New testcase. + 2007-05-25 Paul Thomas <pault@gcc.gnu.org> PR fortran/32047 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-2.c b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-2.c new file mode 100644 index 00000000000..95aa77eb3f7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-2.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-forwprop" } */ + +/* We should be able to optimize this to b->t[i] = 1 during + early optimizations. */ + +struct a +{ + char t[10]; +}; + +struct a *b; + +void f(__SIZE_TYPE__ i) +{ + char *c = b->t; + c[i] = 1; +} + +/* { dg-final { scan-tree-dump "t\\\[i.*\\\] = 1;" "forwprop1" { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump "t\\\[i.*\\\] = 1;" "forwprop2" } } */ +/* { dg-final { cleanup-tree-dump "forwprop?" } } */ diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c index 2afdd9a6332..95f1c003c25 100644 --- a/gcc/tree-ssa-forwprop.c +++ b/gcc/tree-ssa-forwprop.c @@ -513,28 +513,30 @@ forward_propagate_addr_into_variable_array_index (tree offset, tree lhs, if (TREE_CODE (offset) != SSA_NAME) return false; - /* Get the defining statement of the offset before type - conversion. */ - offset = SSA_NAME_DEF_STMT (offset); + /* Try to find an expression for a proper index. This is either + a multiplication expression by the element size or just the + ssa name we came along in case the element size is one. */ + if (integer_onep (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (lhs))))) + index = offset; + else + { + offset = SSA_NAME_DEF_STMT (offset); - /* The statement which defines OFFSET before type conversion - must be a simple GIMPLE_MODIFY_STMT. */ - if (TREE_CODE (offset) != GIMPLE_MODIFY_STMT) - return false; + /* The RHS of the statement which defines OFFSET must be a + multiplication of an object by the size of the array elements. */ + if (TREE_CODE (offset) != GIMPLE_MODIFY_STMT) + return false; - /* The RHS of the statement which defines OFFSET must be a - multiplication of an object by the size of the array elements. - This implicitly verifies that the size of the array elements - is constant. */ - offset = GIMPLE_STMT_OPERAND (offset, 1); - if (TREE_CODE (offset) != MULT_EXPR - || TREE_CODE (TREE_OPERAND (offset, 1)) != INTEGER_CST - || !simple_cst_equal (TREE_OPERAND (offset, 1), - TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (lhs))))) - return false; + offset = GIMPLE_STMT_OPERAND (offset, 1); + if (TREE_CODE (offset) != MULT_EXPR + || TREE_CODE (TREE_OPERAND (offset, 1)) != INTEGER_CST + || !simple_cst_equal (TREE_OPERAND (offset, 1), + TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (lhs))))) + return false; - /* The first operand to the MULT_EXPR is the desired index. */ - index = TREE_OPERAND (offset, 0); + /* The first operand to the MULT_EXPR is the desired index. */ + index = TREE_OPERAND (offset, 0); + } /* Replace the pointer addition with array indexing. */ GIMPLE_STMT_OPERAND (use_stmt, 1) = unshare_expr (def_rhs); |

