This is an archive of the discontinued LLVM Phabricator instance.

[WIP]Forming branch from select aggressively in loop
Needs ReviewPublic

Authored by junbuml on May 12 2017, 1:45 PM.

Details

Summary

When a SelectInst is in a critical path of a loop, we aggressively turn the SelectInst into a branch
so that we rely more on the branch predictor.

This change simply check if the SelectInst is in a single latch of a loop in isFormingBranchFromSelectProfitable().
Most of the changes in this patch is to update LoopInfo when there is any change in CFG.

With this change, I observed 5% performance gain in spec2000/vpr in kryo without any regression in other benchmarks in spec2000/spec2006.

I am sending this out early to get early feedback about the basic idea of this change as I do the tuning/testing in parallel. This is also more test cases.

Diff Detail

Event Timeline

junbuml created this revision.May 12 2017, 1:45 PM
sanjoy added a subscriber: sanjoy.May 14 2017, 12:58 PM
jmolloy edited edge metadata.May 15 2017, 12:41 AM

Hi Jun,

This feels a bit fishy to me. In particular, you don't ever check if the select is actually on the critical path, unlike your comment. For example:

%1 = load %a
%2 = select %1, %3
store %2

This would be turned into a branch based on your patch, but isn't on the critical path.

This is a WIP patch and I posted this to get any early feedback about the overall direction and any detail that need to be considered. Basic idea about this was to use an explicit branch when a SelectInst is in frequently executed blocks (e.g., I simply see if SelectInst is in a single latch block) with the hope of HW branch predictor mostly take the right branch during the execution so that we could avoid executing speculated code for most of the loop iterations. I didn't mean to detect any dependence. Sorry for the confusion.

This was an experimental change to see the impact of aggressive use of branch from SelectInst. Basically, checking if a SelectInst is in a loop latch would be not enough information to determine the profitability of turning a SelectInst into a branch. However, I doubt if the current heuristic used in isFormingBranchFromSelectProfitable(), which simply check if one of select's operands is expensive, is reasonable enough to determine profitability of this transformation.

As a part of improving this transformation, I was trying to see other good place for this in MI level. For me, EarlyIfConv seems to be feasible for this using MachineTraceMetrics. Current EarlyIfConv performs the exactly opposite way of transformation (from branch to select) based on a heuristic which check if extra cycles added in the critical path when using select is more than half of a mispredict penalty. Based on this existing framework in EarlyIfConv, I'm trying to do the select to branch transformation using similar, but opposite way of this heuristic. Can anyone give me any feedback about this approach?

junbuml retitled this revision from [CodeGenPrep]Forming branch from select aggressively in loop to [WIP]Forming branch from select aggressively in loop.May 24 2017, 11:03 AM
junbuml added a reviewer: spatel.
mcrosier resigned from this revision.Jul 26 2017, 6:08 AM
spatel resigned from this revision.May 26 2020, 5:39 AM