ipa-cp: Do not create clones for values outside known value range (PR 102513)
authorMartin Jambor <mjambor@suse.cz>
Thu, 31 Mar 2022 15:14:42 +0000 (17:14 +0200)
committerMartin Jambor <mjambor@suse.cz>
Thu, 31 Mar 2022 15:17:21 +0000 (17:17 +0200)
commitcf68f5a6d20db2aee2f3e674ad3f10e1c458edf9
tree97fbed59a81aab7eb1fc7faacc1c34125434168d
parentf6d65e803623c7ba6c8eb92ce5975fc1b90cd91e
ipa-cp: Do not create clones for values outside known value range (PR 102513)

PR 102513 shows we emit bogus array access warnings when IPA-CP
creates clones specialized for values which it deduces from arithmetic
jump functions describing self-recursive calls.  Those can however be
avoided if we consult the IPA-VR information that the same pass also
has.

The patch below does that at the stage when normally values are only
examined for profitability.  It would be better not to create lattices
describing such bogus values in the first place, however that presents
an ordering problem, the pass currently propagates all information,
and so both constants and VR, in no particular order when processing
SCCs, and so this approach seemed much simpler.

I plan to rearrange the pass so that it clones in multiple passes over
the call graph (or rather the lattice dependence graph) and it feels
natural to only do propagation for these kinds of recursion in the
second or later passes, which would fix the issue more elegantly.

gcc/ChangeLog:

2022-02-14  Martin Jambor  <mjambor@suse.cz>

PR ipa/102513
* ipa-cp.cc (decide_whether_version_node): Skip scalar values
which do not fit the known value_range.

gcc/testsuite/ChangeLog:

2022-02-14  Martin Jambor  <mjambor@suse.cz>

PR ipa/102513
* gcc.dg/ipa/pr102513.c: New test.
gcc/ipa-cp.cc
gcc/testsuite/gcc.dg/ipa/pr102513.c [new file with mode: 0644]