-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[SimplfyCFG] Set MD_prof
for select
used for certain conditional simplifications
#154426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -332,6 +332,16 @@ class SimplifyCFGOpt { | |
} | ||
}; | ||
|
||
// we synthesize a || b as select a, true, b | ||
// we synthesize a && b as select a, b, false | ||
// this function determines if SI is playing one of those roles. | ||
bool isSelectInRoleOfConjunctionOrDisjunction(const SelectInst *SI) { | ||
return ((isa<ConstantInt>(SI->getTrueValue()) && | ||
(dyn_cast<ConstantInt>(SI->getTrueValue())->isOne())) || | ||
(isa<ConstantInt>(SI->getFalseValue()) && | ||
(dyn_cast<ConstantInt>(SI->getFalseValue())->isNullValue()))); | ||
} | ||
|
||
} // end anonymous namespace | ||
|
||
/// Return true if all the PHI nodes in the basic block \p BB | ||
|
@@ -4033,6 +4043,7 @@ static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI, | |
|
||
// Try to update branch weights. | ||
uint64_t PredTrueWeight, PredFalseWeight, SuccTrueWeight, SuccFalseWeight; | ||
SmallVector<uint32_t, 2> MDWeights; | ||
if (extractPredSuccWeights(PBI, BI, PredTrueWeight, PredFalseWeight, | ||
SuccTrueWeight, SuccFalseWeight)) { | ||
SmallVector<uint64_t, 8> NewWeights; | ||
|
@@ -4063,7 +4074,7 @@ static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI, | |
// Halve the weights if any of them cannot fit in an uint32_t | ||
fitWeights(NewWeights); | ||
|
||
SmallVector<uint32_t, 8> MDWeights(NewWeights.begin(), NewWeights.end()); | ||
append_range(MDWeights, NewWeights); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need |
||
setBranchWeights(PBI, MDWeights[0], MDWeights[1], /*IsExpected=*/false); | ||
|
||
// TODO: If BB is reachable from all paths through PredBlock, then we | ||
|
@@ -4100,6 +4111,13 @@ static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI, | |
Value *BICond = VMap[BI->getCondition()]; | ||
PBI->setCondition( | ||
createLogicalOp(Builder, Opc, PBI->getCondition(), BICond, "or.cond")); | ||
if (!ProfcheckDisableMetadataFixes) | ||
if (auto *SI = dyn_cast<SelectInst>(PBI->getCondition())) | ||
if (!MDWeights.empty()) { | ||
assert(isSelectInRoleOfConjunctionOrDisjunction(SI)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: I preferred |
||
setBranchWeights(SI, MDWeights[0], MDWeights[1], | ||
/*IsExpected=*/false); | ||
} | ||
|
||
++NumFoldBranchToCommonDest; | ||
return true; | ||
|
@@ -4812,6 +4830,18 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI, | |
fitWeights(NewWeights); | ||
|
||
setBranchWeights(PBI, NewWeights[0], NewWeights[1], /*IsExpected=*/false); | ||
// Cond may be a select instruction with the first operand set to "true", or | ||
// the second to "false" (see how createLogicalOp works for `and` and `or`) | ||
if (!ProfcheckDisableMetadataFixes) | ||
if (auto *SI = dyn_cast<SelectInst>(Cond)) { | ||
assert(isSelectInRoleOfConjunctionOrDisjunction(SI)); | ||
// The select is predicated on PBICond | ||
assert(dyn_cast<SelectInst>(SI)->getCondition() == PBICond); | ||
// The corresponding probabilities are what was referred to above as | ||
// PredCommon and PredOther. | ||
setBranchWeights(SI, PredCommon, PredOther, | ||
/*IsExpected=*/false); | ||
} | ||
} | ||
|
||
// OtherDest may have phi nodes. If so, add an entry from PBI's | ||
|
Uh oh!
There was an error while loading. Please reload this page.