[llvm] Fix emulated TLS alignment for large variables (PR #171037)
Medha Tiwari via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 23 05:57:42 PST 2026
================
@@ -150,6 +150,17 @@ bool addEmuTlsVar(Module &M, const GlobalVariable *GV) {
Type *GVType = GV->getValueType();
Align GVAlignment = DL.getValueOrABITypeAlignment(GV->getAlign(), GVType);
+ // For larger TLS variables that might be accessed via memcpy/memmove,
+ // use the preferred alignment to ensure the backend can use optimized
+ // vector instructions (e.g., ARM NEON vld1.64 requires 16-byte alignment).
+ // This fixes the mismatch where emulated TLS allocates with lower alignment
+ // than what the code generator assumes.
+ TypeSize TS = DL.getTypeStoreSize(GVType);
+ if (TS.isScalable() || TS.getFixedValue() >= 32) {
----------------
medhatiwari wrote:
Thanks for the review! I've addressed all three points:
1. **Scalable size check removed** - You're right, global variables can't have scalable types. Removed that check.
2. The original 32 was arbitrary. I've updated it to `> 16` which corresponds to the NEON vector register size (128 bits = 16 bytes). Types larger than a single vector register are candidates for vectorized memcpy/memmove, which may use aligned vector load/store instructions.
3. **Added testcase** - Added `llvm/test/CodeGen/ARM/emutls-alignment.ll` which verifies a 64-byte TLS array gets 16-byte alignment.
https://github.com/llvm/llvm-project/pull/171037
More information about the llvm-commits
mailing list