[PATCH] BumpPtrAllocator: remove redundant no-slabs-allocated-yet check

Chandler Carruth chandlerc at google.com
Sat Aug 16 22:56:01 PDT 2014


On Sat, Aug 16, 2014 at 8:01 PM, Hans Wennborg <hans at chromium.org> wrote:

> We already handle the no-slabs case when checking whether the current slab
> is large enough: if no slabs have been allocated, CurPtr and End are both
> 0. alignPtr(0), will still be 0, and so "if (Ptr + Size <= End)" fails.
>
> I measured a 1.5% speed-up with "perf stat -r10 clang -fsyntax-only -w
> gcc.c".
>

LGTM, please submit.


>
> The thing I'd like review for is whether "Ptr + Size <= End" is strictly
> correct. It seems to me that Ptr + Size would often point outside the slab
> object (especially now when Ptr can be 0), and that comparing that with End
> would be undefined behaviour. Perhaps we should really be using intptr_t
> here?
>

Technically, yes... but it can't possibly matter. ;]

The correct fix is to compare the difference of Ptr and End to Size, not to
use intptr_t. Feel free to submit that too if you like. =]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140816/6c6373f7/attachment.html>


More information about the llvm-commits mailing list