ipa-sra: Fix thinko when overriding safe_to_import_accesses (PR 101066)
authorMartin Jambor <mjambor@suse.cz>
Thu, 8 Jul 2021 17:44:41 +0000 (19:44 +0200)
committerMartin Jambor <mjambor@suse.cz>
Thu, 8 Jul 2021 17:45:16 +0000 (19:45 +0200)
commit763121ccd908f52bc666f277ea2cf42110b3aad9
tree617f6adbb3fb3b121a10125d0651b0364d0ac48a
parent9bf9f27ac6db4823628c435da9b242fd82bf8d68
ipa-sra: Fix thinko when overriding safe_to_import_accesses (PR 101066)

The "new" IPA-SRA has a more difficult job than the previous
not-truly-IPA version when identifying situations in which a parameter
passed by reference can be passed into a third function and only thee
converted to one passed by value (and possibly "split" at the same
time).

In order to allow this, two conditions must be fulfilled.  First the
call to the third function must happen before any modifications of
memory, because it could change the value passed by reference.
Second, in order to make sure we do not introduce new (invalid)
dereferences, the call must postdominate the entry BB.

The second condition is actually not necessary if the caller function
is also certain to dereference the pointer but the first one must
still hold.  Unfortunately, the code making this overriding decision
also happen to trigger when the first condition is not fulfilled.
This is fixed in the following patch.

gcc/ChangeLog:

2021-06-16  Martin Jambor  <mjambor@suse.cz>

PR ipa/101066
* ipa-sra.c (class isra_call_summary): New member
m_before_any_store, initialize it in the constructor.
(isra_call_summary::dump): Dump the new field.
(ipa_sra_call_summaries::duplicate): Copy it.
(process_scan_results): Set it.
(isra_write_edge_summary): Stream it.
(isra_read_edge_summary): Likewise.
(param_splitting_across_edge): Only override
safe_to_import_accesses if m_before_any_store is set.

gcc/testsuite/ChangeLog:

2021-06-16  Martin Jambor  <mjambor@suse.cz>

PR ipa/101066
* gcc.dg/ipa/pr101066.c: New test.
gcc/ipa-sra.c
gcc/testsuite/gcc.dg/ipa/pr101066.c [new file with mode: 0644]