]> granicus.if.org Git - llvm/commitdiff
[DemandedBits] Optimize a find()+insert pattern with try_emplace and APInt::operator|=
authorFangrui Song <maskray@google.com>
Sun, 3 Mar 2019 11:12:57 +0000 (11:12 +0000)
committerFangrui Song <maskray@google.com>
Sun, 3 Mar 2019 11:12:57 +0000 (11:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355284 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/DemandedBits.cpp

index 0df47a9eda6ef2a7f611358c7dfde42630e357cc..48412d204dcc7db790982e4f24f633d0bce0c6be 100644 (file)
@@ -402,14 +402,9 @@ void DemandedBits::performAnalysis() {
           // If we've added to the set of alive bits (or the operand has not
           // been previously visited), then re-queue the operand to be visited
           // again.
-          APInt ABPrev(BitWidth, 0);
-          auto ABI = AliveBits.find(I);
-          if (ABI != AliveBits.end())
-            ABPrev = ABI->second;
-
-          APInt ABNew = AB | ABPrev;
-          if (ABNew != ABPrev || ABI == AliveBits.end()) {
-            AliveBits[I] = std::move(ABNew);
+          auto Res = AliveBits.try_emplace(I);
+          if (Res.second || (AB |= Res.first->second) != Res.first->second) {
+            Res.first->second = std::move(AB);
             Worklist.insert(I);
           }
         }