tree-optimization/93946 - fix bogus redundant store removal in FRE, DSE and DOM
authorRichard Biener <rguenther@suse.de>
Tue, 3 Mar 2020 10:01:09 +0000 (11:01 +0100)
committerRichard Biener <rguenther@suse.de>
Tue, 3 Mar 2020 10:02:28 +0000 (11:02 +0100)
commit3d6fd7ce6dc4b6baa11920387d62dc001980aa70
tree8254ced343f8ecb9cdfe76b13dd1680c361cbbef
parent01eb1bb0237a24fe50ed0631857f3dfc31782f54
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.
15 files changed:
gcc/ChangeLog
gcc/alias.c
gcc/alias.h
gcc/dse.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr93946-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr93946-2.c [new file with mode: 0644]
gcc/tree-ssa-alias.c
gcc/tree-ssa-dom.c
gcc/tree-ssa-dse.c
gcc/tree-ssa-pre.c
gcc/tree-ssa-sccvn.c
gcc/tree-ssa-sccvn.h
gcc/tree-ssa-scopedtables.c
gcc/tree-ssa-scopedtables.h