[llvm] [SimplifyCFG] Increase budget for FoldTwoEntryPHINode() if the branch is unpredictable. (PR #98495)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 23 04:52:49 PDT 2024


nikic wrote:

> > I'm wondering if it's possible to remove the `FoldTwoEntryPHINode` altogether and hand it in EarlyIfConversion.
> 
> This is intended to be a minimum viable product for 19.x. That's the reason why it's limited to x86 target for the time being. Moving to EarlyIfConversion can be a next step.

If I understand correctly, EarlyIfConversion already does this optimization, just on the machine level. Currently, it only allows critical path extension by half the mispredict penalty. It would seem reasonable to allow a larger extension for `!unpredictable` branches. So I don't really understand this idea of "implement it in SimplifyCFG now for 19.x and then move it to EarlyIfConversion later". If you plan to move this to EarlyIfConversion I would rather revert this (including from the release branch) and implement it there directly.

My own 2c on SimplifyCFG vs EarlyIfConversion is that doing it in SimplifyCFG can allow it to benefit from other select optimizations in the middle end, at the cost of losing branch based optimizations. Though the way this was implemented, with this transform only running at the very end of the middle-end pipeline, you wouldn't get the benefit of other middle-end optimizations anyway. If interaction with other middle-end optimizations is the reason for having this in SimplifyCFG, it may make sense to have a phase ordering test to demonstrate them.

https://github.com/llvm/llvm-project/pull/98495


More information about the llvm-commits mailing list