[clang] [clang] Refine preferred alignment for x86 globals (PR #185487)
Marco Bartoli via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 10 13:59:31 PDT 2026
================
@@ -1832,6 +1832,7 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const {
uint64_t TypeSize =
!BaseT->isIncompleteType() ? getTypeSize(T.getTypePtr()) : 0;
Align = std::max(Align, getMinGlobalAlignOfVar(TypeSize, VD));
+ Align = std::max(Align, getLargeGlobalPreferredAlign(TypeSize, Align));
----------------
wsxarcher wrote:
Thanks for the valuable explanation, I now realized that our implementation did not cover every possible case as it was tested in production only in Edge where almost all is statically compiled.
I now added all the cases to skip this optimizations based of GlobalObject::canIncreaseAlignment() logic.
By the way this optimization resulted in measurable improvements in our workload.
You mentioned that following llvm opt passes could also do this but it does not seem to work as well as doing it in clang. One example that's easy to test is in the test cases, `clang/test/OpenMP/atomic_capture_codegen.cpp` which with this optimization it avoid using external calls for atomics, while even on -O2 it kept calling them.
https://github.com/llvm/llvm-project/pull/185487
More information about the cfe-commits
mailing list