Skip to content

Commit 186dc9a

Browse files
[CodeGen] Avoid repeated hash lookups (NFC) (llvm#113414)
1 parent 5d6cb6f commit 186dc9a

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

llvm/lib/CodeGen/SelectOptimize.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,25 @@ class SelectOptimizeImpl {
244244
Scaled64 getTrueOpCost(DenseMap<const Instruction *, CostInfo> &InstCostMap,
245245
const TargetTransformInfo *TTI) {
246246
if (isa<SelectInst>(I))
247-
if (auto *I = dyn_cast<Instruction>(getTrueValue()))
248-
return InstCostMap.contains(I) ? InstCostMap[I].NonPredCost
247+
if (auto *I = dyn_cast<Instruction>(getTrueValue())) {
248+
auto It = InstCostMap.find(I);
249+
return It != InstCostMap.end() ? It->second.NonPredCost
249250
: Scaled64::getZero();
251+
}
250252

251253
// Or case - add the cost of an extra Or to the cost of the False case.
252254
if (isa<BinaryOperator>(I))
253-
if (auto I = dyn_cast<Instruction>(getFalseValue()))
254-
if (InstCostMap.contains(I)) {
255+
if (auto I = dyn_cast<Instruction>(getFalseValue())) {
256+
auto It = InstCostMap.find(I);
257+
if (It != InstCostMap.end()) {
255258
InstructionCost OrCost = TTI->getArithmeticInstrCost(
256259
Instruction::Or, I->getType(), TargetTransformInfo::TCK_Latency,
257260
{TargetTransformInfo::OK_AnyValue,
258261
TargetTransformInfo::OP_None},
259262
{TTI::OK_UniformConstantValue, TTI::OP_PowerOf2});
260-
return InstCostMap[I].NonPredCost +
261-
Scaled64::get(*OrCost.getValue());
263+
return It->second.NonPredCost + Scaled64::get(*OrCost.getValue());
262264
}
265+
}
263266

264267
return Scaled64::getZero();
265268
}
@@ -270,15 +273,17 @@ class SelectOptimizeImpl {
270273
getFalseOpCost(DenseMap<const Instruction *, CostInfo> &InstCostMap,
271274
const TargetTransformInfo *TTI) {
272275
if (isa<SelectInst>(I))
273-
if (auto *I = dyn_cast<Instruction>(getFalseValue()))
274-
return InstCostMap.contains(I) ? InstCostMap[I].NonPredCost
276+
if (auto *I = dyn_cast<Instruction>(getFalseValue())) {
277+
auto It = InstCostMap.find(I);
278+
return It != InstCostMap.end() ? It->second.NonPredCost
275279
: Scaled64::getZero();
280+
}
276281

277282
// Or case - return the cost of the false case
278283
if (isa<BinaryOperator>(I))
279284
if (auto I = dyn_cast<Instruction>(getFalseValue()))
280-
if (InstCostMap.contains(I))
281-
return InstCostMap[I].NonPredCost;
285+
if (auto It = InstCostMap.find(I); It != InstCostMap.end())
286+
return It->second.NonPredCost;
282287

283288
return Scaled64::getZero();
284289
}

0 commit comments

Comments
 (0)