Follow up to https://reviews.llvm.org/D104808 and
https://reviews.llvm.org/D105749. The only place that seems to be used
is when defining __BIGGEST_ALIGNMENT__ and when choosing the alignment
for the alloca builtin. It seems that both of these should match the
alignof(max_align_t) which, for emscripten, is currently 8 bytes.
Details
- Reviewers
dschuff
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
I guess this is basically the C version of max_align_t so it should match.
but... this still has the potential to break things.
e.g. it will change the allocation in https://github.com/google/XNNPACK/blob/master/src/xnnpack/allocator.h#L66
ISTR that was one of the projects that had an issue with this the first time around?
True, but I think it's not as likely the break things as that change the max_align_t.. which is more commonly used.
e.g. it will change the allocation in https://github.com/google/XNNPACK/blob/master/src/xnnpack/allocator.h#L66
I don't think it will change anything in that code since __BIGGEST_ALIGNMENT__ >= XNN_ALLOCATION_ALIGNMENT will still hold true both before and after this change (XNN_ALLOCATION_ALIGNMENT == 4 on wasm)
ISTR that was one of the projects that had an issue with this the first time around?
Yes, it should match. Having __BIGGEST_ALIGNMENT__ be 16 for emscripten doesn't make any sense right now.
but... this still has the potential to break things.
e.g. it will change the allocation in https://github.com/google/XNNPACK/blob/master/src/xnnpack/allocator.h#L66
ISTR that was one of the projects that had an issue with this the first time around?
I don't think it will change anything in that code since __BIGGEST_ALIGNMENT__ >= XNN_ALLOCATION_ALIGNMENT will still hold true both before and after this change (XNN_ALLOCATION_ALIGNMENT == 4 on wasm)
Right, that check causes XNN_ALLOCATION_ALIGNMENT to be ignored in favor of using clang's _builtin_alloca() which will be changed by this CL.
I seem to recall that @tlively and I spent a bunch of time with XNNpack chasing down some kind of subtle error that I suspect had to do with alignment, but maybe he remembers that better than I do.
I don't think it will since __BIGGEST_ALIGNMENT__ >= XNN_ALLOCATION_ALIGNMENT will remain true after this change.. so this change should have no effect on that code.
I don't think it will since __BIGGEST_ALIGNMENT__ >= XNN_ALLOCATION_ALIGNMENT will remain true after this change.. so this change should have no effect on that code.
I meant that when __BIGGEST_ALIGNMENT__ >= XNN_ALLOCATION_ALIGNMENT (which was true before and will remain true), then XNNPack uses __builtin_alloca() as the implementation of XNN_SIMD_ALLOCA (which presumably is for allocating SIMD values). This change will reduce the alignment used by __builtin_alloca() from 16 to 8, such that (I think) it is no longer suitable for SIMD values.
Maybe this is a bug in XNNPack (they should maybe be using XNN_ALLOCATION_ALIGNMENT with a value suitable for SIMD?) but given that BIGGEST_ALIGNMENT and alloca seem to be intended for any base type (including SIMD) it wouldn't be surprising if someone else were depending on this too.
which... maybe this is just re-litigating the previous discussion, I don't know. I wonder at what point our ABI should be treating SIMD values as "normal" rather than rare.
XNN_ALLOCATION_ALIGNMENT is 8 under webassembly, which apparently the alignment than xnnpack wants for webassemebly. Using alloca for this is find both before and after this change since both 8 and 18 as fit this requirement.
which... maybe this is just re-litigating the previous discussion, I don't know. I wonder at what point our ABI should be treating SIMD values as "normal" rather than rare.
As far as I can tell the only way this change could break XNNpack if XNN_ALLOCATION_ALIGNMENT = 8 is wrongly set there... as long as that is the correct value for XNN_ALLOCATION_ALIGNMENT I don't see how this change could break it. If XNN_ALLOCATION_ALIGNMENT is set wrongly this change might expose that bug.. but it seems correct to me.
As far as I can tell the only way this change could break XNNpack if XNN_ALLOCATION_ALIGNMENT = 8 is wrongly set there... as long as that is the correct value for XNN_ALLOCATION_ALIGNMENT I don't see how this change could break it. If XNN_ALLOCATION_ALIGNMENT is set wrongly this change might expose that bug.. but it seems correct to me.
yeah, that's actually what my concern is. IIUC as written the code is asking for 8, but it's being masked by our value of BIGGEST_ALIGNMENT.
I suppose we should land this since I think we do want to have it match max_align_t. But it does make me wonder (again) whether our choice of ABI is correct here.
Can you also put something in the emscripten release notes about this?
Presumably this change of change makes most sense in the emscripten ChangeLog right? We don't tend to document emscripten-specific changes in the llvm release notes do we?
Presumably this change of change makes most sense in the emscripten ChangeLog right? We don't tend to document emscripten-specific changes in the llvm release notes do we?
Yes, I think so. Also I think it's more likely to be seen by users in the emscripten changelog
OK to land this? (With a provision that I will add something to the emscripten changelog?)
Yes, on further investigation is seems that there is precedent for having alignof(max_align_t) and __BIGGEST_ALIGNMENT__ be different. See https://github.com/emscripten-core/emscripten/pull/19728