[llvm] [llvm] Ensure propagated constants in the vtable are aligned (PR #136630)

via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 21 16:00:57 PDT 2025


PiJoules wrote:

An alternative approach I tried was using `llvm.memcpy.*` instead of a load and hope that the lowering can "just know" if a load will always be aligned (and produce a normal load) or not (and produce a memcpy). Different experiments I tried just ended up having the intrinsic always lower to a normal load and I was never able to manifest a memcpy in aligned or unaligned cases. I imagine we don't want to unconditionally do a `memcpy` also.

Note this approach can also increase the size of vtables slightly, but here are some ideas we can try to reduce the size:
1. Only constant ints are stored before/after the vtable, so it should be possible to find the smallest possible range of values for a constant-propagated method. If we can statically determine the value can fit in some smaller integer type than it would be stored as, we store it as that smaller type, and at each callsite we extend the value to the original type. For example, if we have functions that return `i64`s but we can assert all the values can fit in an `i16`, then we instead store an `i16` before/after the vtable and at each callsite we zero/sign extend this loaded value to an `i64`.
2. If `i1`s would be stored before/after the vtable, store them at the very end of the rebuilt global. The current implementation may store them right before/after the vtable but doing so forces integers placed before/after them to contain extra padding. These can be reduced if instead we stored all the single-bit constants at the end of the rebuilt global.

https://github.com/llvm/llvm-project/pull/136630


More information about the llvm-commits mailing list