[PATCH] D147022: inline global alias

Yaxun Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 28 20:14:15 PDT 2023


yaxunl added a comment.

In D147022#4228170 <https://reviews.llvm.org/D147022#4228170>, @arsenm wrote:

> 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.



================
Comment at: llvm/include/llvm/IR/InstrTypes.h:1409
   /// invocation or the function signature does not match the call signature.
   Function *getCalledFunction() const {
+    Value *V = getCalledOperand();
----------------
arsenm wrote:
> tra wrote:
> > 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.
> 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 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.


================
Comment at: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp:364
       if (auto *GA = dyn_cast<GlobalAlias>(CalledValue)) {
-        assert(!CalledFunction && "Expected null called function in callsite for alias");
         CalledFunction = dyn_cast<Function>(GA->getAliaseeObject());
----------------
tra wrote:
> 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 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.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147022/new/

https://reviews.llvm.org/D147022



More information about the llvm-commits mailing list