diff options
Diffstat (limited to 'gcc/tree-ssa-forwprop.c')
-rw-r--r-- | gcc/tree-ssa-forwprop.c | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c index 31f2ad71640..8cf6ea12c1a 100644 --- a/gcc/tree-ssa-forwprop.c +++ b/gcc/tree-ssa-forwprop.c @@ -717,6 +717,7 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs, tree *rhsp, *lhsp; gimple use_stmt = gsi_stmt (*use_stmt_gsi); enum tree_code rhs_code; + bool res = true; gcc_assert (TREE_CODE (def_rhs) == ADDR_EXPR); @@ -764,19 +765,26 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs, /* Now see if the LHS node is an INDIRECT_REF using NAME. If so, propagate the ADDR_EXPR into the use of NAME and fold the result. */ if (TREE_CODE (lhs) == INDIRECT_REF - && TREE_OPERAND (lhs, 0) == name - && may_propagate_address_into_dereference (def_rhs, lhs) - && (lhsp != gimple_assign_lhs_ptr (use_stmt) - || useless_type_conversion_p (TREE_TYPE (TREE_OPERAND (def_rhs, 0)), - TREE_TYPE (rhs)))) + && TREE_OPERAND (lhs, 0) == name) { - *lhsp = unshare_expr (TREE_OPERAND (def_rhs, 0)); - fold_stmt_inplace (use_stmt); - tidy_after_forward_propagate_addr (use_stmt); + if (may_propagate_address_into_dereference (def_rhs, lhs) + && (lhsp != gimple_assign_lhs_ptr (use_stmt) + || useless_type_conversion_p + (TREE_TYPE (TREE_OPERAND (def_rhs, 0)), TREE_TYPE (rhs)))) + { + *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; + } + else + /* We can have a struct assignment dereferencing our name twice. + Note that we didn't propagate into the lhs to not falsely + claim we did when propagating into the rhs. */ + res = false; } /* Strip away any outer COMPONENT_REF, ARRAY_REF or ADDR_EXPR @@ -796,7 +804,7 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs, *rhsp = unshare_expr (TREE_OPERAND (def_rhs, 0)); fold_stmt_inplace (use_stmt); tidy_after_forward_propagate_addr (use_stmt); - return true; + return res; } /* Now see if the RHS node is an INDIRECT_REF using NAME. If so, @@ -827,7 +835,7 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs, true, GSI_NEW_STMT); gimple_assign_set_rhs1 (use_stmt, new_rhs); tidy_after_forward_propagate_addr (use_stmt); - return true; + return res; } /* If the defining rhs comes from an indirect reference, then do not convert into a VIEW_CONVERT_EXPR. */ @@ -841,7 +849,7 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs, *rhsp = new_rhs; fold_stmt_inplace (use_stmt); tidy_after_forward_propagate_addr (use_stmt); - return true; + return res; } } @@ -943,19 +951,17 @@ forward_propagate_addr_expr (tree name, tree rhs) { gimple_stmt_iterator gsi = gsi_for_stmt (use_stmt); - push_stmt_changes (&use_stmt); result = forward_propagate_addr_expr_1 (name, rhs, &gsi, single_use_p); /* If the use has moved to a different statement adjust - the update machinery. */ + the update machinery for the old statement too. */ if (use_stmt != gsi_stmt (gsi)) { - pop_stmt_changes (&use_stmt); - use_stmt = gsi_stmt (gsi); update_stmt (use_stmt); + use_stmt = gsi_stmt (gsi); } - else - pop_stmt_changes (&use_stmt); + + update_stmt (use_stmt); } all &= result; |