[llvm-dev] question: preferred alignment vs ABI alignment

Andrew Kelley via llvm-dev llvm-dev at lists.llvm.org
Sat Aug 26 14:10:01 PDT 2017


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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170826/223cc13c/attachment.html>


More information about the llvm-dev mailing list