[llvm] 186dc9a - [CodeGen] Avoid repeated hash lookups (NFC) (#113414)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 4 09:41:12 PST 2024
Author: Kazu Hirata
Date: 2024-11-04T09:41:09-08:00
New Revision: 186dc9a4dfd8ab667c601c76b741e0e4551ad138
URL: https://github.com/llvm/llvm-project/commit/186dc9a4dfd8ab667c601c76b741e0e4551ad138
DIFF: https://github.com/llvm/llvm-project/commit/186dc9a4dfd8ab667c601c76b741e0e4551ad138.diff
LOG: [CodeGen] Avoid repeated hash lookups (NFC) (#113414)
Added:
Modified:
llvm/lib/CodeGen/SelectOptimize.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectOptimize.cpp b/llvm/lib/CodeGen/SelectOptimize.cpp
index 55b0eb71ac11fc..9587534d1170fc 100644
--- a/llvm/lib/CodeGen/SelectOptimize.cpp
+++ b/llvm/lib/CodeGen/SelectOptimize.cpp
@@ -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();
}
@@ -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();
}
More information about the llvm-commits
mailing list