Indirect call of phi/select not converted into direct calls
When calling a phi/select of function pointers, we do not attempt to convert this into a branch over direct calls: https://llvm.godbolt.org/z/6s8PxKcj6
This precludes further optimizations, such as inlining.
@nikic, I've looked into this a bit, but before sending patches I'd like to find out your opinion. Any suggestions / recommendations would be appreciated.
Option 1. Similarly to the pass CallSiteSplitting when we have call uint64 %phi() in some basic block BB,
we can create new basic blocks SplitBB_1, SplitBB_2, SplitBB_3, SplitBB_4, duplicate the instructions from the prefix of BB up until the call and remove them from BB, create a new Phi node inside BB to "collect" the results of
@fn1, @fn2, @fn3, @fn4 (from SplitBB_1, ... , SplitBB_4). One downside of this approach - need a threshold to control the aforementioned duplication.
Option 2. Instead of duplicating the prefix of BB one can introduce an indirect branch (switch) to the newly created basic blocks SplitBB_1, SplitBB_2, SplitBB_3, SplitBB_4.
P.S. What would be the best place for this transformation ?
cc: @fhahn
cc @aeubanks @teresajohnson
I suppose I got cc'ed because of my WPD work, but this seems quite different - at least from the examples in the godbolt link. I'm not very familiar with CallSiteSplitting, but can it be expanded to handle this case? @alexander-shaposhnikov can you show a short example for each of your 2 options?