[PATCH] D144621: [Assignment Tracking][NFC] Avoid doing some work when maps have same keys

Orlando Cazalet-Hyams via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 23 00:19:23 PST 2023


Orlando created this revision.
Orlando added reviewers: StephenTozer, jmorse, scott.linder.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Orlando requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Where the new checks have been added, `SymmetricDifference` - still being built - contains entries for variables present in `A` and not in `B`.
If `SymmetricDifference` is empty at this point it means the variables (map keys) in `A` are a subset of those in `B`, so if `A` and `B` are the same size then we know they're identical.

This reduces the number of instructions retired building some of the CTMark projects in a ReleaseLTO-g configuration (geomean change -0.05% with the best improvement being -0.24% for tramp3d-v4)


https://reviews.llvm.org/D144621

Files:
  llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp


Index: llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
===================================================================
--- llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
+++ llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
@@ -1630,17 +1630,20 @@
   unsigned IntersectSize = Join.size();
   (void)IntersectSize;
 
-  // Add the elements in B with variables that are not in A into
-  // SymmetricDifference.
-  for (const auto &Pair : B) {
-    VariableID Var = Pair.first;
-    if (A.count(Var) == 0)
-      SymmetricDifference.push_back(Var);
-  }
+  // Check if B can possibly contain variables not in A.
+  if (!SymmetricDifference.empty() || A.size() != B.size()) {
+    // Add the elements in B with variables that are not in A into
+    // SymmetricDifference.
+    for (const auto &Pair : B) {
+      VariableID Var = Pair.first;
+      if (A.count(Var) == 0)
+        SymmetricDifference.push_back(Var);
+    }
 
-  // Add SymmetricDifference elements to Join and return the result.
-  for (const auto &Var : SymmetricDifference)
-    Join.insert({Var, LocKind::None});
+    // Add SymmetricDifference elements to Join and return the result.
+    for (const auto &Var : SymmetricDifference)
+      Join.insert({Var, LocKind::None});
+  }
 
   assert(Join.size() == (IntersectSize + SymmetricDifference.size()));
   assert(Join.size() >= A.size() && Join.size() >= B.size());
@@ -1721,17 +1724,20 @@
   unsigned IntersectSize = Join.size();
   (void)IntersectSize;
 
-  // Add the elements in B with variables that are not in A into
-  // SymmetricDifference.
-  for (const auto &Pair : B) {
-    VariableID Var = Pair.first;
-    if (A.count(Var) == 0)
-      SymmetricDifference.push_back(Var);
-  }
+  // Check if B can possibly contain variables not in A.
+  if (!SymmetricDifference.empty() || A.size() != B.size()) {
+    // Add the elements in B with variables that are not in A into
+    // SymmetricDifference.
+    for (const auto &Pair : B) {
+      VariableID Var = Pair.first;
+      if (A.count(Var) == 0)
+        SymmetricDifference.push_back(Var);
+    }
 
-  // Add SymmetricDifference elements to Join and return the result.
-  for (auto Var : SymmetricDifference)
-    Join.insert({Var, Assignment::makeNoneOrPhi()});
+    // Add SymmetricDifference elements to Join and return the result.
+    for (auto Var : SymmetricDifference)
+      Join.insert({Var, Assignment::makeNoneOrPhi()});
+  }
 
   assert(Join.size() == (IntersectSize + SymmetricDifference.size()));
   assert(Join.size() >= A.size() && Join.size() >= B.size());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144621.499750.patch
Type: text/x-patch
Size: 2561 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230223/936c51f1/attachment.bin>


More information about the llvm-commits mailing list