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

This commit is contained in:
Kazu Hirata 2024-11-04 09:41:09 -08:00 committed by GitHub
parent 5d6cb6f78a
commit 186dc9a4df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -244,22 +244,25 @@ public:
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();
}
@ -270,15 +273,17 @@ public:
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();
}