ipa/104303 - miscompilation of gnatmake
authorRichard Biener <rguenther@suse.de>
Thu, 7 Apr 2022 12:07:54 +0000 (14:07 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 7 Apr 2022 13:03:36 +0000 (15:03 +0200)
commit8c0ebaf9f586100920a3c0849fb10e9985d7ae58
tree6d15d0cf669d155035d261647744f8eadb7a8d72
parent88b939b19ab454ab2d932ef292bbc557abe4431c
ipa/104303 - miscompilation of gnatmake

Modref attempts to track memory accesses relative to the base pointers
which are parameters of functions.
If it fails, it still makes difference between unknown memory access and
global memory access.  The second makes it possible to disambiguate with
memory that is not accessible from outside world (i.e. everything that does
not escape from the caller function).  This is useful so we do not punt
when unknown function is called.

The added ref_may_access_global_memory_p ends up using
ptr_deref_may_alias_global_p which does not consider escaped automatic
variables as global.  For modref those are still global since they
can be accessed from functions called.

The following adds a flag to the *_global_p APIs indicating whether
escaped local memory should be considered as global or not and
removes ref_may_access_global_memory_p in favor of using
ref_may_alias_global_p with the flag set to true.

2022-04-07  Richard Biener  <rguenther@suse.de>
    Jan Hubicka  <hubicka@ucw.cz>

PR ipa/104303
* tree-ssa-alias.h (ptr_deref_may_alias_global_p,
ref_may_alias_global_p, ref_may_alias_global_p,
stmt_may_clobber_global_p, pt_solution_includes_global): Add
bool parameters indicating whether escaped locals should be
considered global.
* tree-ssa-structalias.cc (pt_solution_includes_global):
When the new escaped_nonlocal_p flag is true also consider
pt->vars_contains_escaped.
* tree-ssa-alias.cc (ptr_deref_may_alias_global_p):
Pass down new escaped_nonlocal_p flag.
(ref_may_alias_global_p): Likewise.
(stmt_may_clobber_global_p): Likewise.
(ref_may_alias_global_p_1): Likewise.  For decls also
query the escaped solution if true.
(ref_may_access_global_memory_p): Remove.
(modref_may_conflict): Use ref_may_alias_global_p with
escaped locals considered global.
(ref_maybe_used_by_stmt_p): Adjust.
* ipa-fnsummary.cc (points_to_local_or_readonly_memory_p):
Likewise.
* tree-ssa-dse.cc (dse_classify_store): Likewise.
* trans-mem.cc (thread_private_new_memory): Likewise, but
consider escaped locals global.
* tree-ssa-dce.cc (mark_stmt_if_obviously_necessary): Likewise.

* gnat.dg/concat5.adb: New.
* gnat.dg/concat5_pkg1.adb: Likewise.
* gnat.dg/concat5_pkg1.ads: Likewise.
* gnat.dg/concat5_pkg2.adb: Likewise.
* gnat.dg/concat5_pkg2.ads: Likewise.
12 files changed:
gcc/ipa-fnsummary.cc
gcc/testsuite/gnat.dg/concat5.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/concat5_pkg1.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/concat5_pkg1.ads [new file with mode: 0644]
gcc/testsuite/gnat.dg/concat5_pkg2.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/concat5_pkg2.ads [new file with mode: 0644]
gcc/trans-mem.cc
gcc/tree-ssa-alias.cc
gcc/tree-ssa-alias.h
gcc/tree-ssa-dce.cc
gcc/tree-ssa-dse.cc
gcc/tree-ssa-structalias.cc