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-pre.c | |
parent | 01eb1bb0237a24fe50ed0631857f3dfc31782f54 (diff) |
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-pre.c')
-rw-r--r-- | gcc/tree-ssa-pre.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c index eaed4b16ed8..29987d840fd 100644 --- a/gcc/tree-ssa-pre.c +++ b/gcc/tree-ssa-pre.c @@ -1140,7 +1140,8 @@ fully_constant_expression (pre_expr e) static tree translate_vuse_through_block (vec<vn_reference_op_s> operands, - alias_set_type set, tree type, tree vuse, + alias_set_type set, alias_set_type base_set, + tree type, tree vuse, basic_block phiblock, basic_block block, bool *same_valid) { @@ -1156,7 +1157,8 @@ translate_vuse_through_block (vec<vn_reference_op_s> operands, return vuse; unsigned int cnt = param_sccvn_max_alias_queries_per_access; - use_oracle = ao_ref_init_from_vn_reference (&ref, set, type, operands); + use_oracle = ao_ref_init_from_vn_reference (&ref, set, base_set, + type, operands); /* Use the alias-oracle to find either the PHI node in this block, the first VUSE used in this block that is equivalent to vuse or @@ -1535,7 +1537,8 @@ phi_translate_1 (bitmap_set_t dest, { newvuse = translate_vuse_through_block (newoperands.exists () ? newoperands : operands, - ref->set, ref->type, + ref->set, ref->base_set, + ref->type, vuse, phiblock, pred, changed ? NULL : &same_valid); @@ -1551,6 +1554,7 @@ phi_translate_1 (bitmap_set_t dest, unsigned int new_val_id; tree result = vn_reference_lookup_pieces (newvuse, ref->set, + ref->base_set, ref->type, newoperands.exists () ? newoperands : operands, @@ -1608,7 +1612,7 @@ phi_translate_1 (bitmap_set_t dest, if (!newoperands.exists ()) newoperands = operands.copy (); newref = vn_reference_insert_pieces (newvuse, ref->set, - ref->type, + ref->base_set, ref->type, newoperands, result, new_val_id); newoperands = vNULL; @@ -1827,8 +1831,8 @@ value_dies_in_block_x (pre_expr expr, basic_block block) /* Init ref only if we really need it. */ if (ref.base == NULL_TREE - && !ao_ref_init_from_vn_reference (&ref, refx->set, refx->type, - refx->operands)) + && !ao_ref_init_from_vn_reference (&ref, refx->set, refx->base_set, + refx->type, refx->operands)) { res = true; break; @@ -3914,12 +3918,16 @@ compute_avail (void) case VN_REFERENCE: { tree rhs1 = gimple_assign_rhs1 (stmt); - alias_set_type set = get_alias_set (rhs1); + ao_ref rhs1_ref; + ao_ref_init (&rhs1_ref, rhs1); + alias_set_type set = ao_ref_alias_set (&rhs1_ref); + alias_set_type base_set + = ao_ref_base_alias_set (&rhs1_ref); vec<vn_reference_op_s> operands = vn_reference_operands_for_lookup (rhs1); vn_reference_t ref; vn_reference_lookup_pieces (gimple_vuse (stmt), set, - TREE_TYPE (rhs1), + base_set, TREE_TYPE (rhs1), operands, &ref, VN_WALK); if (!ref) { |