[Bug ipa/104303] [12 regression] gnatmake is miscompiled by IPA/modref

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Apr 7 11:47:23 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104303

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Jan Hubicka from comment #6)
> OK, tree-ssa-alias is using:
> 
> if (ref_may_access_global_memory_p (ref))
> 
> to determine if the access to S9b.6_22 may be used by the call.  I expected
> this to return true because memory pointed to S9b.6_22 is escaping and thus
> it is accessible from global memory accesses.

Where does it exactly do this in breaking the testcase?  It seems this
function is "new" (I don't remember adding it), and it doesn't use
ref_may_alias_global_p for some reason ...

[...]

> So this predicate tests something different - it tests if the deref can
> alias global variable, not global memory in a sense of anything accessible
> from outside world.
>
> So I want to also return true on points to set that contains escaped?
> 
> diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc
> index 50bd47b31f3..9e34f76c3cb 100644
> --- a/gcc/tree-ssa-alias.cc
> +++ b/gcc/tree-ssa-alias.cc
> @@ -2578,8 +2578,24 @@ ref_may_access_global_memory_p (ao_ref *ref)
>    if (TREE_CODE (base) == MEM_REF
>        || TREE_CODE (base) == TARGET_MEM_REF)
>      {
> -      if (ptr_deref_may_alias_global_p (TREE_OPERAND (base, 0)))
> +      struct ptr_info_def *pi;
> +      tree ptr = TREE_OPERAND (base, 0);
> +
> +      /* If we end up with a pointer constant here that may point
> +        to global memory.  */
> +      if (TREE_CODE (ptr) != SSA_NAME)
> +       return true;
> +
> +      pi = SSA_NAME_PTR_INFO (ptr);
> +
> +      /* If we do not have points-to information for this variable,
> +        we have to punt.  */
> +      if (!pi)
>         return true;
> +
> +      /* ???  This does not use TBAA to prune globals ptr may not access. 
> */
> +      return pt_solution_includes_global (&pi->pt)
> +            || pi->pt.vars_contains_escaped;
>      }
>    else
>      {

At least it should be consistent with this predicate, so doing sth
special only here doesn't make much sense.

I don't remember why I excluded pt->vars_contains_escaped from
pt_solution_includes_global, the testcase I added also passes with
it checked.

OTOH ref_may_alias_global_p_1 does

static bool
ref_may_alias_global_p_1 (tree base)
{ 
  if (DECL_P (base))
    return is_global_var (base);

so a local escaped variable would not be considered aliasing a global
variable from this.

Maybe for clarity we should add flags (defaulted to true?) to those
predicates indicating whether escaped automatic variables should be
considered "global"?  Or add an explicit ptr_deref_may_alias_escaped ().

For example points_to_local_or_readonly_memory_p () seems to exclude
escaped locals, likewise DSE.

But it seems ref_may_access_global_memory_p would be replaced with
ref_may_alias_global_p (ref, true)?


More information about the Gcc-bugs mailing list