https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120817
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|tnfchris at gcc dot gnu.org |rguenth at gcc dot gnu.org --- Comment #16 from Richard Biener <rguenth at gcc dot gnu.org> --- No, that cannot be required for correct operation. I think DSE is wrong in assessing that the store covers more than 5 bytes. The following fixes it for me diff --git a/gcc/tree-ssa-dse.cc b/gcc/tree-ssa-dse.cc index 5ac4280ee36..51a572316cd 100644 --- a/gcc/tree-ssa-dse.cc +++ b/gcc/tree-ssa-dse.cc @@ -181,10 +181,10 @@ initialize_ao_ref_for_dse (gimple *stmt, ao_ref *write, bool may_def_ok = false) can provide a may-def variant. */ if (may_def_ok) { - ao_ref_init_from_ptr_and_size ( - write, gimple_call_arg (stmt, 0), - TYPE_SIZE_UNIT ( - TREE_TYPE (gimple_call_arg (stmt, stored_value_index)))); + ao_ref_init_from_ptr_and_range ( + write, gimple_call_arg (stmt, 0), true, 0, -1, + tree_to_poly_int64 (TYPE_SIZE ( + TREE_TYPE (gimple_call_arg (stmt, stored_value_index))))); return true; } break; but eventually this boils down to DSE not correctly assessing how alias analysis works, in particular when we run into indirect_ref_may_alias_decl_p we do /* If the pointer based access is bigger than the variable they cannot alias. This is similar to the check below where we use TBAA to increase the size of the pointer based access based on the dynamic type of a containing object we can infer from it. */ poly_int64 dsize2; if (known_size_p (size1) && poly_int_tree_p (DECL_SIZE (base2), &dsize2) && known_lt (dsize2, size1)) return false; and clearly DSE claimed the access was of a size that's larger than the decl. DSE thought there are cases where "may_def_ok", but clearly this wasn't anticipated.