Skip to content

[CodeGen] Avoid repeated hash lookups (NFC) #113414

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions llvm/lib/CodeGen/SelectOptimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,22 +244,25 @@ class SelectOptimizeImpl {
Scaled64 getTrueOpCost(DenseMap<const Instruction *, CostInfo> &InstCostMap,
const TargetTransformInfo *TTI) {
if (isa<SelectInst>(I))
if (auto *I = dyn_cast<Instruction>(getTrueValue()))
return InstCostMap.contains(I) ? InstCostMap[I].NonPredCost
if (auto *I = dyn_cast<Instruction>(getTrueValue())) {
auto It = InstCostMap.find(I);
return It != InstCostMap.end() ? It->second.NonPredCost
: Scaled64::getZero();
}

// Or case - add the cost of an extra Or to the cost of the False case.
if (isa<BinaryOperator>(I))
if (auto I = dyn_cast<Instruction>(getFalseValue()))
if (InstCostMap.contains(I)) {
if (auto I = dyn_cast<Instruction>(getFalseValue())) {
auto It = InstCostMap.find(I);
if (It != InstCostMap.end()) {
InstructionCost OrCost = TTI->getArithmeticInstrCost(
Instruction::Or, I->getType(), TargetTransformInfo::TCK_Latency,
{TargetTransformInfo::OK_AnyValue,
TargetTransformInfo::OP_None},
{TTI::OK_UniformConstantValue, TTI::OP_PowerOf2});
return InstCostMap[I].NonPredCost +
Scaled64::get(*OrCost.getValue());
return It->second.NonPredCost + Scaled64::get(*OrCost.getValue());
}
}

return Scaled64::getZero();
}
Expand All @@ -270,15 +273,17 @@ class SelectOptimizeImpl {
getFalseOpCost(DenseMap<const Instruction *, CostInfo> &InstCostMap,
const TargetTransformInfo *TTI) {
if (isa<SelectInst>(I))
if (auto *I = dyn_cast<Instruction>(getFalseValue()))
return InstCostMap.contains(I) ? InstCostMap[I].NonPredCost
if (auto *I = dyn_cast<Instruction>(getFalseValue())) {
auto It = InstCostMap.find(I);
return It != InstCostMap.end() ? It->second.NonPredCost
: Scaled64::getZero();
}

// Or case - return the cost of the false case
if (isa<BinaryOperator>(I))
if (auto I = dyn_cast<Instruction>(getFalseValue()))
if (InstCostMap.contains(I))
return InstCostMap[I].NonPredCost;
if (auto It = InstCostMap.find(I); It != InstCostMap.end())
return It->second.NonPredCost;

return Scaled64::getZero();
}
Expand Down
Loading