[llvm] [clang-tools-extra] [clang] Dont alter cold function alignment unless using Os (PR #72387)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 20 14:09:50 PST 2023


efriedma-quic wrote:

I'll try describing it a different way.

There are two kinds of alignment. "ABI alignment" is required for the code to function correctly (due to things like architecture constraints, reusing the low bit for member pointers, binary patching).  "Preferred alignment" is additional alignment added by the backend to try to improve performance (because, for example, the CPU you're targeting fetches instructions in aligned 16-byte chunks).

On x86, the "ABI alignment" is 1, unless a function is explicitly marked with an "align" attribute, in which case the "ABI alignment" is the marked alignment.

For the sake of performance, the backend increases the alignment of most functions.  But that's not contractual; it's just an implementation detail.  If your code is relying on the backend to produce some particular alignment without an "align" marking, that's a bug in your code; you're just getting lucky.  So the starting point is that all your code is semantically broken.

Given that as a starting point, it should be clear why you shouldn't be special-casing "cold" functions, and why you shouldn't be relying on the backend's "default" alignment.

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


More information about the llvm-commits mailing list