[PATCH] D24108: X86: Fold tail calls into conditional branches where possible (PR26302)
Maksim Panchenko via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 1 16:55:13 PDT 2016
maksfb added a comment.
In https://reviews.llvm.org/D24108#532166, @mkuper wrote:
> Don't know a lot about tail call handling, so the review with a grain of salt.
> (The large amount of new instructions seems unfortunate, but, as above, I don't know enough about this to say whether this is avoidable...)
> In https://reviews.llvm.org/D24108#531998, @maksfb wrote:
> > @hans: I think it is safe to do this optimization while optimizing for size. If you do it by default it could be a performance regression if you reverse direction of the conditional branch. That's what we found out while testing on a micro benchmark. I believe it's related to the way BTB works on Intel's CPUs. The problem is that unless you are doing LTO or work at the binary level, you don't always know the new direction of the branch.
> Is there a reason to believe the change in direction will cause worse performance, systematically?
> Or is this just a random effect on that particular microbenchmark, and we may gain performance in other cases?
It's hard to say, it will depend on the application. If we assume that the original branch direction was selected intentionally (based on compiler hints, profile, or otherwise) then we probably shouldn't expect a gain from reversing the direction. And in the micro benchmark the negative effect of the reversal severely outweighed a benefit from less instructions executed when direction was the same. Can't speculate beyond the micro benchmark as we weren't able to measure the effect on real-world applications beyond applying it to our jiited code in hhvm. But there we could guarantee the branch direction stayed the same.
More information about the llvm-commits