Skip to content

Commit 802fa92

Browse files
committed
[PredicateInfo] Avoid duplicate hash lookup (NFC)
Use try_emplace to either look up the existing entry or insert it.
1 parent a4e4527 commit 802fa92

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

llvm/lib/Transforms/Utils/PredicateInfo.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -728,16 +728,12 @@ void PredicateInfoBuilder::renameUses(SmallVectorImpl<Value *> &OpsToRename) {
728728

729729
PredicateInfoBuilder::ValueInfo &
730730
PredicateInfoBuilder::getOrCreateValueInfo(Value *Operand) {
731-
auto OIN = ValueInfoNums.find(Operand);
732-
if (OIN == ValueInfoNums.end()) {
733-
// This will grow it
731+
auto Res = ValueInfoNums.try_emplace(Operand, ValueInfos.size());
732+
if (Res.second) {
733+
// Allocate space for new ValueInfo.
734734
ValueInfos.resize(ValueInfos.size() + 1);
735-
// This will use the new size and give us a 0 based number of the info
736-
auto InsertResult = ValueInfoNums.insert({Operand, ValueInfos.size() - 1});
737-
assert(InsertResult.second && "Value info number already existed?");
738-
return ValueInfos[InsertResult.first->second];
739735
}
740-
return ValueInfos[OIN->second];
736+
return ValueInfos[Res.first->second];
741737
}
742738

743739
const PredicateInfoBuilder::ValueInfo &

0 commit comments

Comments
 (0)