diff options
Diffstat (limited to 'gcc/tree-ssa-pre.c')
-rw-r--r-- | gcc/tree-ssa-pre.c | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c index c35806a9332..dea04804a88 100644 --- a/gcc/tree-ssa-pre.c +++ b/gcc/tree-ssa-pre.c @@ -53,6 +53,7 @@ along with GCC; see the file COPYING3. If not see #include "ipa-utils.h" #include "tree-cfgcleanup.h" #include "langhooks.h" +#include "alias.h" /* TODO: @@ -4224,26 +4225,36 @@ eliminate_dom_walker::before_dom_children (basic_block b) && !is_gimple_reg (gimple_assign_lhs (stmt)) && (TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME || is_gimple_min_invariant (gimple_assign_rhs1 (stmt)))) - { - tree val; + { + tree val; tree rhs = gimple_assign_rhs1 (stmt); - val = vn_reference_lookup (gimple_assign_lhs (stmt), - gimple_vuse (stmt), VN_WALK, NULL, false); - if (TREE_CODE (rhs) == SSA_NAME) - rhs = VN_INFO (rhs)->valnum; - if (val - && operand_equal_p (val, rhs, 0)) - { - if (dump_file && (dump_flags & TDF_DETAILS)) - { - fprintf (dump_file, "Deleted redundant store "); - print_gimple_stmt (dump_file, stmt, 0, 0); - } + vn_reference_t vnresult; + val = vn_reference_lookup (lhs, gimple_vuse (stmt), VN_WALKREWRITE, + &vnresult, false); + if (TREE_CODE (rhs) == SSA_NAME) + rhs = VN_INFO (rhs)->valnum; + if (val + && operand_equal_p (val, rhs, 0)) + { + /* We can only remove the later store if the former aliases + at least all accesses the later one does or if the store + was to readonly memory storing the same value. */ + alias_set_type set = get_alias_set (lhs); + if (! vnresult + || vnresult->set == set + || alias_set_subset_of (set, vnresult->set)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Deleted redundant store "); + print_gimple_stmt (dump_file, stmt, 0, 0); + } - /* Queue stmt for removal. */ - el_to_remove.safe_push (stmt); - continue; - } + /* Queue stmt for removal. */ + el_to_remove.safe_push (stmt); + continue; + } + } } /* If this is a control statement value numbering left edges |