[llvm] [SystemZ][z/OS] Honor alignment of global data (PR #208095)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 7 13:55:41 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-mc
Author: Kai Nacke (redstar)
<details>
<summary>Changes</summary>
The alignment of sections is set after the section are created. Thus, the ED structure set at object construction time is updated with the current section alignment. This only applies to ED type section. As result, the alignment of global data is correctly set.
---
Full diff: https://github.com/llvm/llvm-project/pull/208095.diff
3 Files Affected:
- (modified) llvm/include/llvm/MC/MCSectionGOFF.h (+10-2)
- (added) llvm/test/CodeGen/SystemZ/zos-align.ll (+28)
- (modified) llvm/test/CodeGen/SystemZ/zos-section-1.ll (+1-1)
``````````diff
diff --git a/llvm/include/llvm/MC/MCSectionGOFF.h b/llvm/include/llvm/MC/MCSectionGOFF.h
index 288f9038bb65e..3a2c03dfa4b34 100644
--- a/llvm/include/llvm/MC/MCSectionGOFF.h
+++ b/llvm/include/llvm/MC/MCSectionGOFF.h
@@ -35,7 +35,7 @@ class LLVM_ABI MCSectionGOFF final : public MCSection {
// The attributes of the GOFF symbols.
union {
GOFF::SDAttr SDAttributes;
- GOFF::EDAttr EDAttributes;
+ mutable GOFF::EDAttr EDAttributes;
GOFF::PRAttr PRAttributes;
};
@@ -67,7 +67,9 @@ class LLVM_ABI MCSectionGOFF final : public MCSection {
GOFF::EDAttr EDAttributes, MCSectionGOFF *Parent)
: MCSection(Name, K.isText(), IsVirtual, nullptr), Parent(Parent),
EDAttributes(EDAttributes), SymbolType(GOFF::ESD_ST_ElementDefinition),
- IsBSS(K.isBSS()), RequiresNonZeroLength(0), Emitted(0) {}
+ IsBSS(K.isBSS()), RequiresNonZeroLength(0), Emitted(0) {
+ setAlignment(Align(1 << EDAttributes.Alignment));
+ }
MCSectionGOFF(StringRef Name, SectionKind K, bool IsVirtual,
GOFF::PRAttr PRAttributes, MCSectionGOFF *Parent)
@@ -96,6 +98,12 @@ class LLVM_ABI MCSectionGOFF final : public MCSection {
}
GOFF::EDAttr getEDAttributes() const {
assert(isED() && "Not a ED section");
+ // Update alignment.
+ uint8_t Log = Log2(getAlign());
+ if (Log <= GOFF::ESD_ALIGN_4Kpage)
+ EDAttributes.Alignment = static_cast<GOFF::ESDAlignment>(Log);
+ else
+ llvm_unreachable("Unsupported alignment");
return EDAttributes;
}
GOFF::PRAttr getPRAttributes() const {
diff --git a/llvm/test/CodeGen/SystemZ/zos-align.ll b/llvm/test/CodeGen/SystemZ/zos-align.ll
new file mode 100644
index 0000000000000..59827dec16079
--- /dev/null
+++ b/llvm/test/CodeGen/SystemZ/zos-align.ll
@@ -0,0 +1,28 @@
+; Test alignment of global constants
+;
+; RUN: llc < %s -mtriple=s390x-ibm-zos -mcpu=z10 | FileCheck %s
+
+ at data = global [8 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7], align 4096
+
+; CHECK: * @data
+; CHECK-NEXT: data CSECT
+; CHECK-NEXT: C_WSA64 CATTR ALIGN(12),FILL(0),DEFLOAD,NOTEXECUTABLE,RMODE(64),PART(dat
+; CHECK-NEXT: ta)
+; CHECK-NEXT: data XATTR LINKAGE(XPLINK),REFERENCE(DATA),SCOPE(EXPORT)
+; CHECK-NEXT: DS 0B
+; CHECK-NEXT: * 0x0
+; CHECK-NEXT: DC XL4'00000000'
+; CHECK-NEXT: * 0x1
+; CHECK-NEXT: DC XL4'00000001'
+; CHECK-NEXT: * 0x2
+; CHECK-NEXT: DC XL4'00000002'
+; CHECK-NEXT: * 0x3
+; CHECK-NEXT: DC XL4'00000003'
+; CHECK-NEXT: * 0x4
+; CHECK-NEXT: DC XL4'00000004'
+; CHECK-NEXT: * 0x5
+; CHECK-NEXT: DC XL4'00000005'
+; CHECK-NEXT: * 0x6
+; CHECK-NEXT: DC XL4'00000006'
+; CHECK-NEXT: * 0x7
+; CHECK-NEXT: DC XL4'00000007'
diff --git a/llvm/test/CodeGen/SystemZ/zos-section-1.ll b/llvm/test/CodeGen/SystemZ/zos-section-1.ll
index c5020fcb9f24a..f4b9667d5d915 100644
--- a/llvm/test/CodeGen/SystemZ/zos-section-1.ll
+++ b/llvm/test/CodeGen/SystemZ/zos-section-1.ll
@@ -46,7 +46,7 @@ entry:
; CHECK-NEXT: 0000b0 00 00 00 00 00 00 00 00 00 00 00 {{..}} 00 00 00 00
; CHECK-NEXT: 0000c0 00 00 00 00 00 00 00 00 01 80 00 00 00 00 00 00
; CHECK-NEXT: 0000d0 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 08
-; CHECK-NEXT: 0000e0 00 00 03 00 00 00 00 08 c3 6d c3 d6 c4 c5 f6 f4
+; CHECK-NEXT: 0000e0 00 00 04 00 00 00 00 08 c3 6d c3 d6 c4 c5 f6 f4
; ESD record, type ED.
; The name is C_@@QPPA2.
``````````
</details>
https://github.com/llvm/llvm-project/pull/208095
More information about the llvm-commits
mailing list