Track nondeterminism and interposable calls in ipa-modref
authorJan Hubicka <jh@suse.cz>
Sun, 14 Nov 2021 23:10:06 +0000 (00:10 +0100)
committerJan Hubicka <jh@suse.cz>
Sun, 14 Nov 2021 23:10:06 +0000 (00:10 +0100)
commita34edf9a3e907de25929b1103a4b37af858c7917
tree09a613250d0d99564a39e7b334b878ecceda2525
parent3057f1ab737582a9fb37a3fb967ed8bf3659f2f4
Track nondeterminism and interposable calls in ipa-modref

Adds tracking of two new flags in ipa-modref: nondeterministic and
calls_interposable.  First is set when function does something that is not
guaranteed to be the same if run again (volatile memory access, volatile asm or
external function call).  Second is set if function calls something that
does not bind to current def.

nondeterministic enables ipa-modref to discover looping pure/const functions
and it now discovers 138 of them during cc1plus link (which about doubles
number of such functions detected late).  We however can do more

 1) We can extend FRE to eliminate redundant calls.
    I filled a PR103168 for that.
    A common case are inline functions that are not autodetected as ECF_CONST
    just becuase they do not bind to local def and can be easily handled.
    More tricky is to use modref summary to check what memory locations are
    read.
 2) DSE can eliminate redundant stores

The calls_interposable flag currently also improves tree-ssa-structalias
on functions that are not binds_to_current_def since reads_global_memory
is now not cleared by interposable functions.

gcc/ChangeLog:

* ipa-modref.h (struct modref_summary): Add nondeterministic
and calls_interposable flags.
* ipa-modref.c (modref_summary::modref_summary): Initialize new flags.
(modref_summary::useful_p): Check new flags.
(struct modref_summary_lto): Add nondeterministic and
calls_interposable flags.
(modref_summary_lto::modref_summary_lto): Initialize new flags.
(modref_summary_lto::useful_p): Check new flags.
(modref_summary::dump): Dump new flags.
(modref_summary_lto::dump): Dump new flags.
(ignore_nondeterminism_p): New function.
(merge_call_side_effects): Merge new flags.
(process_fnspec): Likewise.
(analyze_load): Volatile access is nondeterministic.
(analyze_store): Liekwise.
(analyze_stmt): Volatile ASM is nondeterministic.
(analyze_function): Clear new flags.
(modref_summaries::duplicate): Duplicate new flags.
(modref_summaries_lto::duplicate): Duplicate new flags.
(modref_write): Stream new flags.
(read_section): Stream new flags.
(propagate_unknown_call): Update new flags.
(modref_propagate_in_scc): Propagate new flags.
* tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Check
calls_interposable.
* tree-ssa-structalias.c (determine_global_memory_access):
Likewise.
gcc/ipa-modref.c
gcc/ipa-modref.h
gcc/tree-ssa-alias.c
gcc/tree-ssa-structalias.c