diff options
author | Richard Biener <rguenther@suse.de> | 2020-03-03 11:01:09 +0100 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2020-03-03 11:02:28 +0100 |
commit | 3d6fd7ce6dc4b6baa11920387d62dc001980aa70 (patch) | |
tree | 8254ced343f8ecb9cdfe76b13dd1680c361cbbef /gcc/tree-ssa-dom.c | |
parent | 01eb1bb0237a24fe50ed0631857f3dfc31782f54 (diff) | |
download | gcc-3d6fd7ce6dc4b6baa11920387d62dc001980aa70.zip gcc-3d6fd7ce6dc4b6baa11920387d62dc001980aa70.tar.gz gcc-3d6fd7ce6dc4b6baa11920387d62dc001980aa70.tar.bz2 |
tree-optimization/93946 - fix bogus redundant store removal in FRE, DSE and DOM
This fixes a common mistake in removing a store that looks redudnant but
is not because it changes the dynamic type of the memory and thus makes
a difference for following loads with TBAA.
2020-03-03 Richard Biener <rguenther@suse.de>
PR tree-optimization/93946
* alias.h (refs_same_for_tbaa_p): Declare.
* alias.c (refs_same_for_tbaa_p): New function.
* tree-ssa-alias.c (ao_ref_alias_set): For a NULL ref return
zero.
* tree-ssa-scopedtables.h
(avail_exprs_stack::lookup_avail_expr): Add output argument
giving access to the hashtable entry.
* tree-ssa-scopedtables.c (avail_exprs_stack::lookup_avail_expr):
Likewise.
* tree-ssa-dom.c: Include alias.h.
(dom_opt_dom_walker::optimize_stmt): Validate TBAA state before
removing redundant store.
* tree-ssa-sccvn.h (vn_reference_s::base_set): New member.
(ao_ref_init_from_vn_reference): Adjust prototype.
(vn_reference_lookup_pieces): Likewise.
(vn_reference_insert_pieces): Likewise.
* tree-ssa-sccvn.c: Track base alias set in addition to alias
set everywhere.
(eliminate_dom_walker::eliminate_stmt): Also check base alias
set when removing redundant stores.
(visit_reference_op_store): Likewise.
* dse.c (record_store): Adjust valdity check for redundant
store removal.
* gcc.dg/torture/pr93946-1.c: New testcase.
* gcc.dg/torture/pr93946-2.c: Likewise.
Diffstat (limited to 'gcc/tree-ssa-dom.c')
-rw-r--r-- | gcc/tree-ssa-dom.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index 1dbfb38..eea494c 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -49,6 +49,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-vrp.h" #include "vr-values.h" #include "gimple-ssa-evrp-analyze.h" +#include "alias.h" /* This file implements optimizations on the dominator tree. */ @@ -2155,9 +2156,14 @@ dom_opt_dom_walker::optimize_stmt (basic_block bb, gimple_stmt_iterator *si, else new_stmt = gimple_build_assign (rhs, lhs); gimple_set_vuse (new_stmt, gimple_vuse (stmt)); + expr_hash_elt *elt = NULL; cached_lhs = m_avail_exprs_stack->lookup_avail_expr (new_stmt, false, - false); - if (cached_lhs && operand_equal_p (rhs, cached_lhs, 0)) + false, &elt); + if (cached_lhs + && operand_equal_p (rhs, cached_lhs, 0) + && refs_same_for_tbaa_p (elt->expr ()->kind == EXPR_SINGLE + ? elt->expr ()->ops.single.rhs + : NULL_TREE, lhs)) { basic_block bb = gimple_bb (stmt); unlink_stmt_vdef (stmt); |