Skip to content

Discriminants may not want to all be as small as possible #11551

Closed
@alexcrichton

Description

@alexcrichton

If I have a struct Option<uint>, the way that we represent this today is via struct { u8 tag; uint value; }. This is ideal for discriminant size, and even for struct size. The bad part is that we add explicit padding (7 bytes on 64-bit machines) to make up for the middle padding. This leads to horrible things like unaligned moves in LLVM and alloca's of 7 bytes.

I believe that it may actually be better for a discriminant to be the smallest size above or equal to the maximum alignment of the struct. So in the above case the discriminant would actually become uint, and for Option<u8> it would remain u8. This would remove any padding between the discriminant and the beginning of the data.

cc @jld, I think this would remove some need for tbaa.struct for now, although we'll still want that eventually. I'm also not sure if reading a word is more efficient than reading a byte, but it kinda seems so to me?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions