[PATCH] D57033: [SSAUpdater] Handle case with single available value faster.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 21 12:44:37 PST 2019


fhahn created this revision.
fhahn added reviewers: efriedma, davide, mzolotukhin.
Herald added subscribers: dmgreen, hiraditya.

If there is only a single available value, all uses must be dominated by
that value and there is no need to search for a reaching definition.

This speeds up SSAUpdater in some cases. For the test case
from PR37202, it speeds up LCSSA construction by 4 times. Alternatively
we could also special case this in LCSSA.cpp.

Time-passes without this patch for test case from PR37202:

  Total Execution Time: 29.9285 seconds (29.9276 wall clock)
  
  ---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
  5.2786 ( 17.7%)   0.0021 (  1.2%)   5.2806 ( 17.6%)   5.2808 ( 17.6%)  Unswitch loops
  4.3739 ( 14.7%)   0.0303 ( 18.1%)   4.4042 ( 14.7%)   4.4042 ( 14.7%)  Loop-Closed SSA Form Pass
  4.2658 ( 14.3%)   0.0192 ( 11.5%)   4.2850 ( 14.3%)   4.2851 ( 14.3%)  Loop-Closed SSA Form Pass #2
  2.2307 (  7.5%)   0.0013 (  0.8%)   2.2320 (  7.5%)   2.2318 (  7.5%)  Loop Invariant Code Motion
  2.0888 (  7.0%)   0.0012 (  0.7%)   2.0900 (  7.0%)   2.0897 (  7.0%)  Unroll loops
  1.6761 (  5.6%)   0.0013 (  0.8%)   1.6774 (  5.6%)   1.6774 (  5.6%)  Value Propagation
  1.3686 (  4.6%)   0.0029 (  1.8%)   1.3716 (  4.6%)   1.3714 (  4.6%)  Induction Variable Simplification
  1.1457 (  3.8%)   0.0010 (  0.6%)   1.1468 (  3.8%)   1.1468 (  3.8%)  Loop-Closed SSA Form Pass #4
  1.1384 (  3.8%)   0.0005 (  0.3%)   1.1389 (  3.8%)   1.1389 (  3.8%)  Loop-Closed SSA Form Pass #6
  1.1360 (  3.8%)   0.0027 (  1.6%)   1.1387 (  3.8%)   1.1387 (  3.8%)  Loop-Closed SSA Form Pass #5
  1.1331 (  3.8%)   0.0010 (  0.6%)   1.1341 (  3.8%)   1.1340 (  3.8%)  Loop-Closed SSA Form Pass #3

Time passes with this patch

  Total Execution Time: 20.7313 seconds (20.7312 wall clock)
  
   ---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
   4.5299 ( 22.0%)   0.0050 (  2.8%)   4.5349 ( 21.9%)   4.5352 ( 21.9%)  Unswitch loops
   2.3655 ( 11.5%)   0.0032 (  1.8%)   2.3687 ( 11.4%)   2.3685 ( 11.4%)  Unroll loops
   1.9314 (  9.4%)   0.0034 (  1.9%)   1.9348 (  9.3%)   1.9350 (  9.3%)  Loop Invariant Code Motion
   1.7423 (  8.5%)   0.0002 (  0.1%)   1.7425 (  8.4%)   1.7424 (  8.4%)  Value Propagation
   1.4688 (  7.1%)   0.0037 (  2.1%)   1.4726 (  7.1%)   1.4727 (  7.1%)  Induction Variable Simplification
   1.2353 (  6.0%)   0.0189 ( 10.5%)   1.2541 (  6.0%)   1.2541 (  6.0%)  Loop-Closed SSA Form Pass #2
   1.2042 (  5.9%)   0.0246 ( 13.7%)   1.2288 (  5.9%)   1.2288 (  5.9%)  Loop-Closed SSA Form Pass
   0.7451 (  3.6%)   0.0009 (  0.5%)   0.7461 (  3.6%)   0.7458 (  3.6%)  Unroll loops #2
   0.4745 (  2.3%)   0.0015 (  0.9%)   0.4761 (  2.3%)   0.4761 (  2.3%)  Loop-Closed SSA Form Pass #4
   0.4714 (  2.3%)   0.0032 (  1.8%)   0.4746 (  2.3%)   0.4746 (  2.3%)  Loop-Closed SSA Form Pass #6
   0.4709 (  2.3%)   0.0009 (  0.5%)   0.4717 (  2.3%)   0.4717 (  2.3%)  Loop-Closed SSA Form Pass #3
   0.4661 (  2.3%)   0.0001 (  0.1%)   0.4662 (  2.2%)   0.4662 (  2.2%)  Loop-Closed SSA Form Pass #5


https://reviews.llvm.org/D57033

Files:
  llvm/lib/Transforms/Utils/SSAUpdater.cpp


Index: llvm/lib/Transforms/Utils/SSAUpdater.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SSAUpdater.cpp
+++ llvm/lib/Transforms/Utils/SSAUpdater.cpp
@@ -64,7 +64,13 @@
 }
 
 Value *SSAUpdater::FindValueForBlock(BasicBlock *BB) const {
-  AvailableValsTy::iterator AVI = getAvailableVals(AV).find(BB);
+  auto &AvailableVals = getAvailableVals(AV);
+  // If there is only a single available value, this value dominates all users,
+  // so we can just use it here.
+  if (AvailableVals.size() == 1)
+    return AvailableVals.begin()->second;
+
+  AvailableValsTy::iterator AVI = AvailableVals.find(BB);
   return (AVI != getAvailableVals(AV).end()) ? AVI->second : nullptr;
 }
 
@@ -322,6 +328,12 @@
 /// placement of PHIs and then inserting new PHIs where needed.
 Value *SSAUpdater::GetValueAtEndOfBlockInternal(BasicBlock *BB) {
   AvailableValsTy &AvailableVals = getAvailableVals(AV);
+
+  // If there is only a single available value, this value dominates all users,
+  // so we can just use it here.
+  if (AvailableVals.size() == 1)
+    return AvailableVals.begin()->second;
+
   if (Value *V = AvailableVals[BB])
     return V;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57033.182820.patch
Type: text/x-patch
Size: 1195 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190121/87c46866/attachment.bin>


More information about the llvm-commits mailing list