This is an archive of the discontinued LLVM Phabricator instance.

[CodeGenPrepare.cpp] Feedback on changing logic when to convert select to branch
Needs ReviewPublic

Authored by Gerolf on Oct 27 2014, 12:03 AM.

Details

Reviewers
grosbach
hfinkel
Summary

The current logic in OptimizeSelectInst() converts a
select to a branch when the select is expensive (determined by a (sub-)target
specific flag) or the branch is cheaper (by some heuristic). The proposed change
enables the heuristic check to kick in even when the target specific flag
suggest any select is cheap and therefore should not be converted. Eventually we want good
heuristics when to prefer a branch over a select. Changing the condition when to
enable them is the first step doing so. At least on cyclone treating all selects
as 'cheap' results in regressions. I'm still evaluating the peformance impact of this change,
and look for feedback on the general direction.

Diff Detail

Event Timeline

Gerolf updated this revision to Diff 15472.Oct 27 2014, 12:03 AM
Gerolf retitled this revision from to [CodeGenPrepare.cpp] Feedback on changing logic when to convert select to branch.
Gerolf updated this object.
Gerolf edited the test plan for this revision. (Show Details)
Gerolf added reviewers: grosbach, chandlerc, jmolloy.
Gerolf added a subscriber: Unknown Object (MLST).
jmolloy edited edge metadata.Oct 27 2014, 8:28 AM

Hi Gerolf,

The concept looks fine to me, there's no real functionality change here. One inline comment though.

James

lib/CodeGen/CodeGenPrepare.cpp
3069

Don't you want "isFormingBranchFromSelectProfitable(SI)" here?

This change concerns me, there are certainly targets on which the branch really is always more expensive. If you need to make the TLI interface more expressive, then feel free to do so, but don't remove a target's ability to turn off the select to branch conversion.

@hfinkel

The proposed change would make this very easy if it turns out to be necessary. In this case for architectures where the branch is *always* more expensive make sure
a) PredictableSelectIsExpensive=false (default for all arch)
b) add a target specific call in isFormingBranchFromSelectProfitable(SI) that overrides any heuristic by saying something like “select is always cheaper than branch”.

For which targets do you suggest adding b)? The only possible candidates are !Cortex, !"LikeA9", Atom:

./lib/CodeGen/TargetLoweringBase.cpp: PredictableSelectIsExpensive = false; (default)
./lib/Target/AArch64/AArch64ISelLowering.cpp: if (Subtarget->isCortexA57()) PredictableSelectIsExpensive = true;
./lib/Target/ARM/ARMISelLowering.cpp: PredictableSelectIsExpensive = Subtarget->isLikeA9();
./lib/Target/R600/AMDGPUISelLowering.cpp: PredictableSelectIsExpensive = false; (looks redundant)
./lib/Target/X86/X86ISelLowering.cpp: PredictableSelectIsExpensive = !Subtarget->isAtom();

FWIW, I have not found a regression on x86 or ARM for the change.

chandlerc resigned from this revision.Mar 29 2015, 2:10 PM
chandlerc edited reviewers, added: hfinkel; removed: chandlerc.

Removing myself as reviewer, Hal has pointed out a specific concern with this patch.