<div dir="ltr">Sparse bit vector is going to be slow unless you can turn it into mostly real set operations.<br><div>But it should be able to be turned into mostly real set operations.</div><div>It would be a lot of work though</div><div>(staring at it, i mean it iterates a lot and does things one by one, like defs and kills. That will never be faster on sparsebitvector.</div><div><br></div><div>If the set of defs/kills was a mask or something you could union/intersect at once, then it would be much faster).</div><div><br></div><div>The GCC version of live regs, which has subregs, and does the same thing with sparse bit vectors, doesn't take any appreciable time on these testcases  :(</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 10, 2017 at 8:20 PM, Davide Italiano via Phabricator <span dir="ltr"><<a href="mailto:reviews@reviews.llvm.org" target="_blank">reviews@reviews.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">davide created this revision.<br>
<br>
The testcase in <a href="https://bugs.llvm.org/show_bug.cgi?id=32984" rel="noreferrer" target="_blank">https://bugs.llvm.org/show_<wbr>bug.cgi?id=32984</a> went from 3 minutes to 10 minutes after a change that made the LoopUnroll pass more aggressive (increasing the threshold).<br>
<br>
`-time-passes` reveals large part of the time is spent in `PHI Elimination` (in the backend).<br>
My profiling shows all the time of PHI elimination goes to `llvm::LiveVariables::<wbr>addNewBlock`. This is because we keep Defs/Kills registers in a SmallSet, and `lvm/ADT/SmallSet.h ->   VIterator vfind(const T &V);` is `O(N)`.<br>
<br>
Switching to a DenseSet reduces the time spent in the pass from 297 seconds to 97 seconds. Profiling still shows a lot of time is spent iterating the data structure, so I guess there's room for improvement.<br>
<br>
I tried a `SparseBitVector` and it's slightly slower than the `DenseMap` solution. I wanted to try a `BitVector` but I'm not sure I have an upper bound on the number of elements.<br>
<br>
<br>
<a href="https://reviews.llvm.org/D33088" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D33088</a><br>
<br>
Files:<br>
  lib/CodeGen/LiveVariables.cpp<br>
<br>
<br>
Index: lib/CodeGen/LiveVariables.cpp<br>
==============================<wbr>==============================<wbr>=======<br>
--- lib/CodeGen/LiveVariables.cpp<br>
+++ lib/CodeGen/LiveVariables.cpp<br>
@@ -767,7 +767,7 @@<br>
                                 MachineBasicBlock *SuccBB) {<br>
   const unsigned NumNew = BB->getNumber();<br>
<br>
-  SmallSet<unsigned, 16> Defs, Kills;<br>
+  DenseSet<unsigned, 16> Defs, Kills;<br>
<br>
   MachineBasicBlock::iterator BBI = SuccBB->begin(), BBE = SuccBB->end();<br>
   for (; BBI != BBE && BBI->isPHI(); ++BBI) {<br>
<br>
<br>
</blockquote></div><br></div>