[cfe-commits] [PATCH] clang ext_vector_type alignment in packed structure

Eli Friedman eli.friedman at gmail.com
Thu Mar 22 15:41:55 PDT 2012


On Fri, Mar 16, 2012 at 9:09 AM, Schoedel, Kevin P
<kevin.p.schoedel at intel.com> wrote:
> [Revised to add a comment; resending to cfe-commits rather than llvm-commits]
>
> 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.

r153285.

-Eli




More information about the cfe-commits mailing list