[llvm] r290768 - [LVI] Remove count/erase idiom in favor of checking result value of erase
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 30 14:09:10 PST 2016
Author: reames
Date: Fri Dec 30 16:09:10 2016
New Revision: 290768
URL: http://llvm.org/viewvc/llvm-project?rev=290768&view=rev
Log:
[LVI] Remove count/erase idiom in favor of checking result value of erase
Minor compile time win. Avoids an additional O(N) scan in the case where we are removing an element and costs nothing when we aren't.
Modified:
llvm/trunk/lib/Analysis/LazyValueInfo.cpp
Modified: llvm/trunk/lib/Analysis/LazyValueInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LazyValueInfo.cpp?rev=290768&r1=290767&r2=290768&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LazyValueInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/LazyValueInfo.cpp Fri Dec 30 16:09:10 2016
@@ -462,8 +462,7 @@ void LazyValueInfoCache::eraseValue(Valu
SmallVector<AssertingVH<BasicBlock>, 4> ToErase;
for (auto &I : OverDefinedCache) {
SmallPtrSetImpl<Value *> &ValueSet = I.second;
- if (ValueSet.count(V))
- ValueSet.erase(V);
+ ValueSet.erase(V);
if (ValueSet.empty())
ToErase.push_back(I.first);
}
@@ -533,12 +532,9 @@ void LazyValueInfoCache::threadEdgeImpl(
bool changed = false;
for (Value *V : ValsToClear) {
- // TODO: count and erase can be converted to a find/erase(itr) pattern
- if (!ValueSet.count(V))
+ if (!ValueSet.erase(V))
continue;
- ValueSet.erase(V);
-
// If we removed anything, then we potentially need to update
// blocks successors too.
changed = true;
More information about the llvm-commits
mailing list