This is an archive of the discontinued LLVM Phabricator instance.

inline global alias
Needs RevisionPublic

Authored by yaxunl on Mar 27 2023, 8:58 PM.

Details

Summary

Currently, llvm does not inline functions called through alias.
This causes performance degradation on Windows compared
with Linux, since on Windows some constructors are emitted
as aliases to other constructors.

This patch allows functions called through alias to be inlined.

Diff Detail

Event Timeline

yaxunl created this revision.Mar 27 2023, 8:58 PM
yaxunl requested review of this revision.Mar 27 2023, 8:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 27 2023, 8:58 PM
Herald added a subscriber: wdng. · View Herald Transcript
tra added inline comments.Mar 28 2023, 10:36 AM
llvm/include/llvm/IR/InstrTypes.h
1409

Are we sure that there are no users of these getCalledFunction functions that would expect them to return nullptr when we deal with an alias?

Unless someone familiar with the code says that it's OK to treat aliases as functions here, I would try to keep effect of the change limited to the area where we're making a decision to inline the function or alias.

llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
364

The fact that aliases were mentioned in this assertion make me wonder if there is a reason aliases are not inlined that I'm not aware of.

I'm out of my depth here, and would like to hear from someone who may know what's going on.

I thought calls to aliases were generally folded to direct calls at some point, so is there just an ordering issue?

llvm/include/llvm/IR/InstrTypes.h
1409

I do think getCalledFunction is a hazardous function where most users do the wrong thing. This will continue to miss constantexpr casts. Could also stripPointerCastsAndAliases. I'm not sure if we want to change this or not

I thought calls to aliases were generally folded to direct calls at some point, so is there just an ordering issue?

I searched references of GlobalAlias in LLVM code and could not find a pass doing that.

llvm/include/llvm/IR/InstrTypes.h
1409

I checked the references of getCalledFunction. It seems most cases they do not care whether a function is called through alias. However, there are situations where alias may be different from its aliasee.

I could add an optional parameter AllowAlias to getCalledFunction and by default off. Then turn it on where it makes sense.

llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
364

I checked alias definition in LLVM manual (https://llvm.org/docs/LangRef.html#aliases). It seems to me the only situation we cannot inline an alias is when it has an optional weak linkage whereas the aliasee does not. Otherwise the alias and the aliasee is equivalent to the inliner.

I added more reviewers in the hope that we can get an answer why alias cannot be inlined.

asl added inline comments.Mar 28 2023, 9:40 PM
llvm/include/llvm/IR/AbstractCallSite.h
225

If an alias has weak linkage, then it could be overridden by a strong definition. So you cannot resolve alias to aliasee in such case. Same for the case below

nikic requested changes to this revision.Mar 29 2023, 12:13 AM
nikic added a reviewer: pcc.
nikic added subscribers: pcc, nikic.

Adding @pcc for alias optimizations.

llvm/include/llvm/IR/InstrTypes.h
1409

getCalledFunction() is explicitly not supposed to look through bitcasts, let alone aliases. Use getCalledOperand()->stripPointerCastsAndAliases() in places where you think stripping aliases is safe.

This revision now requires changes to proceed.Mar 29 2023, 12:13 AM