As a frontend developer using LLVM, in practice, it works fine to always use ABI alignment for things.
However let’s talk about what’s optimally correct.
If I have a type that I know only is usable internally and no pointers to it will ever be exposed to external modules, I should be able to use preferred alignment for it. For example, I could create a global variable with preferred alignment, and then use the same alignment for loads and stores.
But what if I put it in a struct?
LLVM will then use the DataLayout to align the struct. Is that going to use ABI alignment or preferred alignment? Is there a way to configure alignment on a per-field basis of a struct?
If I use a packed struct and manually order fields and set my own padding in the packed struct to align according to preferred alignment, is that going to compromise any optimization passes?
Is there an optimization pass that removes unused fields from a struct? If so there should also be an intrinsic function to get the offset in bytes of a field - this would serve both as a reference to the field, as well as allowing LLVM to re-order fields and remove fields. I don’t think this exists, but would such a feature be welcome if I were to create a patch?