[PATCH] ADT: Shave a pointer off of SmallVector<T, 1>

Sean Silva chisophugis at gmail.com
Tue Jun 30 20:52:31 PDT 2015


Is there a specific place where we're storing SmallVectors in a
datastructure that you're trying to optimize with this? It might be worth
investing in a more general small-sizeof vector than TinyPtrVector. The way
the SmallVector currently works (such as actually containing a 3 pointer
"vector header") imposes some fundamental limitations on its sizeof.

There are various standard ways to greatly reduce sizeof of vectors
especially in 64-bit address spaces (and certain assumptions on the OS...)
where often the high bits are redundant, allowing the vector header to be
compressed to a single pointer in size across a very large size range. Even
without the spacious high-bits of a 64-bit address space, we can often
store at least up to size 4 or 8 in the low bits, which for many use cases
is plenty in the common case.

(to be clear, I think this patch makes sense; just had a high-level
question)

-- Sean Silva

On Tue, Jun 30, 2015 at 5:34 PM, Duncan P. N. Exon Smith <
dexonsmith at apple.com> wrote:

> I'd just commit this, but I want to check:
>
>  1. Are my static asserts valid under MSVC?  Sanitizers?  If not, what
>     *is* a portable way to check that we don't waste memory here?
>  2. I like them in SmallVector.h (assuming they're portable).
>     Anyone strongly prefer ADTTests?
>
> Avoid an unused byte -- which for `sizeof(T) >= sizeof(void *)` costs
> a pointer -- on `SmallVector<T, 1>`.  Shave the same byte off of
> `SmallVector<T, 0>`.  Otherwise, no functionality change.
>
> Note that `SmallVector<T, 0>` has the same memory footprint as
> `SmallVector<T, 1>`, which seems like a bug to me.  We should probably
> fix that too.
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150630/f93f6b01/attachment.html>


More information about the llvm-commits mailing list