I am trying to get LLVM to optimize an indirect call to a branching control flow with a direct call and an indirect call.
What I mean is, transform this:
%funcptr = select i1 %condition, void()* @known_function, void ()* %loaded_address %result = tail call void %funcptr()
br i1 %condition, label %if.true, label %if.false if.true: tail call void @ known_function() br label %if.end if.false: tail call void %loaded_address() br label %if.end if.end:
Can LLVM do this perhaps when I add metadata about probabilities of %condition being true or not, or is this not possible at all?
(The reason for my question is a virtual call optimization after profiling. @known_function is simple and inlinable, which I think results in a faster code path when %condition is almost always true. It is very similar to the Indirect Call Promotion currently being implemented as PGO option.)