]> git.ipfire.org Git - thirdparty/gcc.git/commit
ipa: Avoid duplicate replacements in IPA-SRA transformation phase
authorMartin Jambor <mjambor@suse.cz>
Thu, 4 Apr 2024 20:46:16 +0000 (22:46 +0200)
committerMartin Jambor <mjambor@suse.cz>
Thu, 4 Apr 2024 20:56:48 +0000 (22:56 +0200)
commitca56b43105fc09021ec445f1978a17cd85ae5e0c
treed9e1db19be1a26ba35d956e68a915ce4385c4902
parenta24476422ba311b83737cf8bdc5892a7fc7514eb
ipa: Avoid duplicate replacements in IPA-SRA transformation phase

When the analysis part of IPA-SRA figures out that it would split out
a scalar part of an aggregate which is known by IPA-CP to contain a
known constant, it skips it knowing that the transformation part looks
at IPA-CP aggregate results too and does the right thing (which can
include doing the propagation in GIMPLE because that is the last
moment the parameter exists).

However, when IPA-SRA wants to split out a smaller aggregate out
of an aggregate, which happens to be of the same size as a known
scalar constant at the same offset, the transformation bit fails to
recognize the situation, tries to do both splitting and constant
propagation and in PR 111571 testcase creates a nonsensical call
statement on which the call redirection then ICEs.

Fixed by making sure we don't try to do two replacements of the same
part of the same parameter.

The look-up among replacements requires these are sorted and this
patch just sorts them if they are not already sorted before each new
look-up.  The worst number of sortings that can happen is number of
parameters which are both split and have aggregate constants times
param_ipa_max_agg_items (default 16).  I don't think complicating the
source code to optimize for this unlikely case is worth it but if need
be, it can of course be done.

gcc/ChangeLog:

2024-03-15  Martin Jambor  <mjambor@suse.cz>

PR ipa/111571
* ipa-param-manipulation.cc
(ipa_param_body_adjustments::common_initialization): Avoid creating
duplicate replacement entries.

gcc/testsuite/ChangeLog:

2024-03-15  Martin Jambor  <mjambor@suse.cz>

PR ipa/111571
* gcc.dg/ipa/pr111571.c: New test.
gcc/ipa-param-manipulation.cc
gcc/testsuite/gcc.dg/ipa/pr111571.c [new file with mode: 0644]