aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-forwprop.c
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2007-05-25 09:07:29 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2007-05-25 09:07:29 +0000
commit88efe45a92a6b6b3e0a1767143af61436f75052b (patch)
tree6502eb3dfad884611a31270c8024502f2d16a26a /gcc/tree-ssa-forwprop.c
parent36032710357e5af5f3743c46c29c457e2b04ed05 (diff)
downloadgcc-88efe45a92a6b6b3e0a1767143af61436f75052b.zip
gcc-88efe45a92a6b6b3e0a1767143af61436f75052b.tar.gz
gcc-88efe45a92a6b6b3e0a1767143af61436f75052b.tar.bz2
re PR tree-optimization/31982 (Missed forw prop with indirect ref and addr. (and char types or sizeof(type) == 1))
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. Co-Authored-By: Andrew Pinski <andrew_pinski@playstation.sony.com> From-SVN: r125058
Diffstat (limited to 'gcc/tree-ssa-forwprop.c')
-rw-r--r--gcc/tree-ssa-forwprop.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c
index 2afdd9a..95f1c00 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);