Skip to content

[PowerPC] Alignment of toc-data symbol should not be increased during optimizations #94593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/docs/LangRef.rst
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,10 @@ doesn't). These kinds of structs (we may call them homogeneous scalable vector
structs) are considered sized and can be used in loads, stores, allocas, but
not GEPs.

Globals with ``toc-data`` attribute set are stored in TOC of XCOFF. Their
alignments are not larger than that of a TOC entry. Optimizations should not
increase their alignments to mitigate TOC overflow.

Syntax::

@<GlobalVarName> = [Linkage] [PreemptionSpecifier] [Visibility]
Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/IR/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,16 @@ bool GlobalObject::canIncreaseAlignment() const {
if (isELF && !isDSOLocal())
return false;

// GV with toc-data attribute is defined in a TOC entry. To mitigate TOC
// overflow, the alignment of such symbol should not be increased. Otherwise,
// padding is needed thus more TOC entries are wasted.
bool isXCOFF =
(!Parent || Triple(Parent->getTargetTriple()).isOSBinFormatXCOFF());
if (isXCOFF)
if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
if (GV->hasAttribute("toc-data"))
return false;

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/PowerPC/tocdata-firm-alignment.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ target triple = "powerpc-ibm-aix7.2.0.0"

%struct.widget = type { i8, i8, i8 }

; CHECK: @global = {{.*}}constant %struct.widget { i8 4, i8 0, i8 0 }, align 8 #0
; CHECK: @global = {{.*}}constant %struct.widget { i8 4, i8 0, i8 0 }, align 4 #0
@global = constant %struct.widget { i8 4, i8 0, i8 0 }, align 4 #0

define void @baz() #1 {
Expand Down
Loading