Why optimize AvailableExternallyLinkage functions when codegenning?

AvailableExternallyLinkage functions are not emitted when codegenning, do they really need to go through optimization passes?

I tried testing with

bool FPPassManager::runOnFunction(Function &F) {
if (F.isDeclaration() || F.hasAvailableExternallyLinkage())

which failed only one test, LLVM :: CodeGen/X86/hidden-vis-pic.ll, so there is some issue which yet may be solved without doing all the passes.

AvailableExternally functions are available for inlining, if inlining them makes sense. The inliner makes better decisions after some early optimisation (SROA, CSE, at least). We can’t rely on this having been done prior to (partial) linking.

David

This make sense.
There are quite a few passes after inlining, so not processing AvailableExternally after inlining would save work or are there additional considerations?

We have a pass that drops them. Maybe it could be ran earlier.

Cheers,
Rafael

As a ModulePass it can run just after the Call Graph SCC Pass Manager, so
some extra work would still be done inside the SCC Pass Manager for
available externally functions.
Maybe we can do better in doing something while inside the Call Graph SCC
Pass Manager but this is simple change and saves many ModulePasses between
the SCC and last DCE.