diff options
author | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-11-17 20:58:52 +0000 |
---|---|---|
committer | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-11-17 20:58:52 +0000 |
commit | 1870058bbd1796d93f22ca732cbce9cea00f4f10 (patch) | |
tree | 2fda85eef94cf204f819a91ac43fc189c8adafb3 /gcc/tree-ssa-forwprop.c | |
parent | 4ccb87dfc5e9dcea3ca006397b538c6612d7bcdb (diff) | |
download | gcc-1870058bbd1796d93f22ca732cbce9cea00f4f10.tar.gz |
PR middle-end/38140
* tree-ssa-forwprop.c (forward_propagate_addr_expr_1): If
propagating x = &a into *x = b, add a cast if not useless
type conversion or don't optimize if another stmt would be
needed.
* gcc.dg/pr38140.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@141949 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-ssa-forwprop.c')
-rw-r--r-- | gcc/tree-ssa-forwprop.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c index 5626b103429..333ef828473 100644 --- a/gcc/tree-ssa-forwprop.c +++ b/gcc/tree-ssa-forwprop.c @@ -721,13 +721,28 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs, && TREE_OPERAND (lhs, 0) == name && may_propagate_address_into_dereference (def_rhs, lhs)) { - *lhsp = unshare_expr (TREE_OPERAND (def_rhs, 0)); - fold_stmt_inplace (use_stmt); - tidy_after_forward_propagate_addr (use_stmt); + bool valid = true; + if (lhsp == gimple_assign_lhs_ptr (use_stmt) + && !useless_type_conversion_p (TREE_TYPE (TREE_OPERAND (def_rhs, 0)), + TREE_TYPE (rhs)) + && !CONVERT_EXPR_CODE_P (rhs_code)) + { + if (rhs_code == SSA_NAME) + gimple_assign_set_rhs_code (use_stmt, NOP_EXPR); + else + valid = false; + } + if (valid) + { + *lhsp = unshare_expr (TREE_OPERAND (def_rhs, 0)); + fold_stmt_inplace (use_stmt); + tidy_after_forward_propagate_addr (use_stmt); - /* Continue propagating into the RHS if this was not the only use. */ - if (single_use_p) - return true; + /* Continue propagating into the RHS if this was not the only + use. */ + if (single_use_p) + return true; + } } /* Strip away any outer COMPONENT_REF, ARRAY_REF or ADDR_EXPR |