This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Use PredictableSelectIsExpensive to enable select to branch in CGP
ClosedPublic

Authored by ZhangKang on Dec 25 2019, 6:16 PM.

Details

Summary

There is a patch D19488: [CodeGenPrepare] use branch weight metadata to decide if a select should be turned into a branch, this patch is for CGP, it will try to convert SELECT to branch based on the BranchProbability, when the BranchProbability more than MinPercentageForPredictableBranch(default value is 99%).
The variable PredictableSelectExpensive can be set whether we will do this SELECT to branch optimization, the default value is false. Now only ARM and X86 has set this variable like this:

For PPC, we should also set the variable PredictableSelectIsExpensive to do the select to if based on BranchProbability in CodeGenPrepare.

Diff Detail

Event Timeline

ZhangKang created this revision.Dec 25 2019, 6:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 25 2019, 6:16 PM
ZhangKang added reviewers: Restricted Project, hfinkel.Jan 1 2020, 9:40 PM
nemanjai added inline comments.Jan 3 2020, 5:28 AM
llvm/lib/Target/PowerPC/PPC.td
292

This should certainly be set for Power8 as well.

llvm/lib/Target/PowerPC/PPCISelLowering.cpp
1285

I think that having the same name PredictableSelectIsExpensive as members of both the TLI and the Subtarget is a bit confusing. At the very least, the comment should be a bit more descriptive. Perhaps:

// Let the subtarget (CPU) decide if a predictable select is more
// expensive than the corresponding branch. This information is used
// in CGP to decide when to convert selects into branches.
llvm/lib/Target/PowerPC/PPCSubtarget.h
143

For the sake of convention, leave this uninitialized here and initialize it in PPCSubtarget::initializeEnvironment() just like all the rest of these.

ZhangKang marked 5 inline comments as done.Jan 6 2020, 10:42 PM
ZhangKang added inline comments.
llvm/lib/Target/PowerPC/PPC.td
292

I haven't do the performance for the Power8, so I only enable it for Power9.

llvm/lib/Target/PowerPC/PPCISelLowering.cpp
1285

Have modified the comments.

ZhangKang updated this revision to Diff 236523.Jan 6 2020, 10:45 PM
ZhangKang marked 2 inline comments as done.

Modified the patch to follow Nemanjai's comments.

ZhangKang updated this revision to Diff 244910.Feb 16 2020, 6:58 PM

Modify the test case and add set the FeaturePredictableSelectIsExpensive for power8.

ZhangKang marked an inline comment as done.Feb 16 2020, 7:00 PM
ZhangKang added inline comments.
llvm/lib/Target/PowerPC/PPC.td
292

Have set the FeaturePredictableSelectIsExpensive for Power8.

ZhangKang updated this revision to Diff 244911.Feb 16 2020, 7:18 PM

Update the full context.

jsji set the repository for this revision to rG LLVM Github Monorepo.Mar 2 2020, 8:32 AM
nemanjai accepted this revision.Apr 7 2020, 2:21 PM

LGTM.

This revision is now accepted and ready to land.Apr 7 2020, 2:21 PM
This revision was automatically updated to reflect the committed changes.