[llvm] Fix emulated TLS alignment for large variables (PR #171037)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 23 11:29:39 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) {
----------------
efriedma-quic wrote:

16 still seems arbitrary.  For example, 32-bit Arm ldm has an alignment constraint of 4 bytes.

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


More information about the llvm-commits mailing list