[PATCH] D139034: [IR] GEP: Fix byte-offsets in vectors of overaligned types
Jannik Silvanus via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 30 10:20:53 PST 2022
jsilvanus created this revision.
Herald added subscribers: jdoerfert, hiraditya.
Herald added a project: All.
jsilvanus requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Vectors contain their elements tightly packed together without
any padding bytes. If the elements have stricter-than-natural
alignment requirements, then the elements in the vector are smaller
than in for example an array or struct.
This fact was not accounted for when computing byte-offsets of GEPs.
For example, with `i16:32` alignment, the byte-offset of the following
GEP was incorrectly computed as 8 bytes, while 4 bytes is correct:
getelementptr <3 x i16>, <3 x i16> *%ptr, i32 0, i32 2
To fix, instead of unconditionally using the elements' AllocSize,
use a new helper `getElementSize(..)` that returns the inner type's
size if the outer type is a vector, otherwise its AllocSize.
Add a unit test.
Also add an assertion to SROA:
SROA tries to generate "natural" GEPs for a given byte offset if possible,
instead of bitcasting to i8* and applying the offset there.
Add an assertion that such a generated natural GEP results in the correct
byte offset. This assertion would have failed prior to the GEP fix.
Update the LangRef to be more explicit on the layout of vectors of
overaligned elements.
The lit test is new. I'll precommit it if this patch is accepted.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D139034
Files:
llvm/docs/LangRef.rst
llvm/include/llvm/IR/GetElementPtrTypeIterator.h
llvm/include/llvm/IR/Operator.h
llvm/lib/IR/Operator.cpp
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/test/Transforms/SROA/overaligned-datalayout.ll
llvm/unittests/IR/InstructionsTest.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139034.479011.patch
Type: text/x-patch
Size: 11999 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221130/1f3bf3b4/attachment.bin>
More information about the llvm-commits
mailing list