[PATCH] D33088: [LiveVariables] Switch Kill/Defs sets to be `DenseSet`

Daniel Berlin via llvm-commits llvm-commits at lists.llvm.org
Wed May 10 20:34:28 PDT 2017


Sparse bit vector is going to be slow unless you can turn it into mostly
real set operations.
But it should be able to be turned into mostly real set operations.
It would be a lot of work though
(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.

If the set of defs/kills was a mask or something you could union/intersect
at once, then it would be much faster).

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  :(



On Wed, May 10, 2017 at 8:20 PM, Davide Italiano via Phabricator <
reviews at reviews.llvm.org> wrote:

> davide created this revision.
>
> The testcase in https://bugs.llvm.org/show_bug.cgi?id=32984 went from 3
> minutes to 10 minutes after a change that made the LoopUnroll pass more
> aggressive (increasing the threshold).
>
> `-time-passes` reveals large part of the time is spent in `PHI
> Elimination` (in the backend).
> My profiling shows all the time of PHI elimination goes to
> `llvm::LiveVariables::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)`.
>
> 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.
>
> 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.
>
>
> https://reviews.llvm.org/D33088
>
> Files:
>   lib/CodeGen/LiveVariables.cpp
>
>
> Index: lib/CodeGen/LiveVariables.cpp
> ===================================================================
> --- lib/CodeGen/LiveVariables.cpp
> +++ lib/CodeGen/LiveVariables.cpp
> @@ -767,7 +767,7 @@
>                                  MachineBasicBlock *SuccBB) {
>    const unsigned NumNew = BB->getNumber();
>
> -  SmallSet<unsigned, 16> Defs, Kills;
> +  DenseSet<unsigned, 16> Defs, Kills;
>
>    MachineBasicBlock::iterator BBI = SuccBB->begin(), BBE = SuccBB->end();
>    for (; BBI != BBE && BBI->isPHI(); ++BBI) {
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170510/e407e95d/attachment.html>


More information about the llvm-commits mailing list