ipa-sra: Forward propagation of sizes which are safe to dereference
authorMartin Jambor <mjambor@suse.cz>
Tue, 13 Dec 2022 23:33:06 +0000 (00:33 +0100)
committerMartin Jambor <mjambor@suse.cz>
Tue, 13 Dec 2022 23:58:30 +0000 (00:58 +0100)
commitf2cf4c6121d2b350bb66ed6763e81b77a585846d
tree0c1bedcd8c92a3c22043e1711c410e38282bb6dd
parente3a5cc3259ea173f74e34094c1eeffec7ccd9fe1
ipa-sra: Forward propagation of sizes which are safe to dereference

The previous patch established a way to propagate information about
parameters from callers to callees (even though then the actual
splitting is done in the opposite direction), this patch adds to that
information about size of the parameters that is known to be safe to
dereference in the callers - the information currently does not come
from actual dereferences but only when we pass a reference to a known
declaration, but we can use e.g. dereferences in BBs dominating the
call, for example too, if we decide it is worth it.

References which look like splitting candidates but are not always
dereferenced are - assuming the dereferences are not improbable - not
discarded straight away but only marked as conditionally
dereferenceable.  IPA phase then makes sure that they stay candidates
only if all incoming edges have big enough known-to-be-safe size.

gcc/ChangeLog:

2022-11-11  Martin Jambor  <mjambor@suse.cz>

* ipa-sra.cc (isra_param_desc): New fields safe_size,
conditionally_dereferenceable and safe_size_set.
(struct gensum_param_desc): New field conditionally_dereferenceable.
(struct isra_param_flow): Updated comment of field unit_size.
(ipa_sra_function_summaries::duplicate): Copy the new fields.
(isra_call_summary::dump): Dump unit_size when representing safe_size.
(dump_gensum_param_descriptor): Dump new flag.
(dump_isra_param_descriptor): Dump new fields.
(isra_analyze_call): Fill unit_size when it represents known safe
size.
(check_gensum_access): Instead of disqualifying pointers which are not
always dereference, mark them as conditionally dereferencable if loads
are frequent enough.
(process_scan_results): Copy the conditionally_dereferenceable flag.
(isra_write_node_summary): Stream new fields, or assert they are not
initialized yet.
(isra_read_node_info): Stream new fields.
(update_safe_size): New function.
(propagate_param_hints_accross_call): Propagate safe_sizes.
(propagate_hints_to_all_callees): New function.
(adjust_parameter_descriptions): Check conditionally_dereferenceable
candidates, rework dumping.
(ipa_sra_analysis): Move most of hint propagation for one node to
propagate_hints_to_all_callees.  Add another loop to stabilize within
SCCs and another one to verify.

gcc/testsuite/ChangeLog:

2022-11-11  Martin Jambor  <mjambor@suse.cz>

* gcc.dg/ipa/ipa-sra-26.c: New test.
* gcc.dg/ipa/ipa-sra-27.c: Likewise.
* gcc.dg/ipa/ipa-sra-28.c: Likewise.
gcc/ipa-sra.cc
gcc/testsuite/gcc.dg/ipa/ipa-sra-26.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/ipa/ipa-sra-27.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/ipa/ipa-sra-28.c [new file with mode: 0644]