[NewPM][Inliner] Check if deleted function is in current SCC
authorArthur Eubanks <aeubanks@google.com>
Tue, 20 Jul 2021 21:51:12 +0000 (14:51 -0700)
committerArthur Eubanks <aeubanks@google.com>
Wed, 21 Jul 2021 15:47:45 +0000 (08:47 -0700)
commit8bc298d041fbe8ec2cabe8a05c6cb06beff5527f
tree32981140e741203757ff7c7e1a4cf38e662c5ea2
parent4de74a7c4da3516d0d9119452cc073b061716b5d
[NewPM][Inliner] Check if deleted function is in current SCC

In weird cases, the inliner will inline internal recursive functions,
sometimes causing them to have no more uses, in which case the
inliner will mark the function to be deleted. The function is
actually deleted after the call to
updateCGAndAnalysisManagerForCGSCCPass(). In
updateCGAndAnalysisManagerForCGSCCPass(), UR.UpdatedC may be set to
the SCC containing the function to be deleted. Then the inliner calls
CG.removeDeadFunction() which can cause that SCC to be deleted, even
though it's still stored in UR.UpdatedC.

We could potentially check in the wrappers/pass managers if UR.UpdatedC
is in UR.InvalidatedSCCs before doing anything with it, but it's safer
to do this as close to possible to the call to CG.removeDeadFunction()
to avoid issues with allocating a new SCC in the same address as
the deleted one.

It's hard to find a small test case since we need to have recursive
internal functions be reachable from non-internal functions, yet they
need to become non-recursive and not referenced by other functions when
inlined.

Similar to https://reviews.llvm.org/D106306.

Fixes PR50788.

Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D106405
llvm/lib/Transforms/IPO/Inliner.cpp
llvm/test/Transforms/Inline/deleted-scc.ll [new file with mode: 0644]