[llvm-commits] PATCH: clang ext_vector_type alignment in packed structure
Eli Friedman
eli.friedman at gmail.com
Wed Mar 14 11:41:10 PDT 2012
On Wed, Mar 14, 2012 at 11:10 AM, Schoedel, Kevin P
<kevin.p.schoedel at intel.com> wrote:
> This time with the patch....
>
> When an ext_vector_type appears inside a structure, clang's CodeGen
> does not supply an alignment on loads and stores. Because of this,
> InstCombine subsequently adds an alignment based purely on the type,
> which is incorrect in the case that the structure is packed.
>
> For example,
>
> typedef float float4 __attribute__((ext_vector_type(4)));
>
> struct __attribute__((packed, aligned(4))) packed_struct {
> unsigned int use_some_space; float4 position;
> };
>
> static float f(struct packed_struct *p) {
> return p->position.x;
> }
>
> yields
>
> %1 = load <4 x float>* %position
>
> which after InstCombine becomes
>
> %1 = load <4 x float>* %position, align 16
>
> even though the 'position' member is aligned only to 4 bytes.
>
> The attached patch adds code to CGExpr.cpp to propagate the (estimated)
> alignment of the underlying element. Please review and commit if
> appropriate.
Might want to add a comment to CGValue.h explicitly stating that the
alignment associated with a VectorElt lvalue is the alignment of the
whole vector. Otherwise, looks fine.
-Eli
More information about the llvm-commits
mailing list