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

Schoedel, Kevin P kevin.p.schoedel at intel.com
Fri Mar 16 09:09:43 PDT 2012

[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;


    %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.

Kevin Schoedel kevin.p.schoedel at intel.com +1-519-772-2580 SSG-DPD-ECDL-DMP - Intel Dynamic Mobility and Parallelism

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1919-clang-04.patch
Type: application/octet-stream
Size: 6125 bytes
Desc: 1919-clang-04.patch
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120316/a922df2e/attachment.obj>

More information about the cfe-commits mailing list