[llvm] 117921e - [PowerPC] Alignment of toc-data symbol should not be increased during optimizations (#94593)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 17 18:58:40 PDT 2024
Author: Kai Luo
Date: 2024-06-18T09:58:37+08:00
New Revision: 117921e071a353edbd27f08456ec27ea98ecdb8c
URL: https://github.com/llvm/llvm-project/commit/117921e071a353edbd27f08456ec27ea98ecdb8c
DIFF: https://github.com/llvm/llvm-project/commit/117921e071a353edbd27f08456ec27ea98ecdb8c.diff
LOG: [PowerPC] Alignment of toc-data symbol should not be increased during optimizations (#94593)
Currently, the alignment of toc-data symbol might be changed during
instcombine
```
IC: Visiting: %global = alloca %struct.widget, align 8
Found alloca equal to global: %global = alloca %struct.widget, align 8
memcpy = call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %global, ptr align 1 @global, i64 3, i1 false)
```
The `alloca` is created with `PrefAlign` which is 8 and after IC, the
alignment of `@global` is enforced into `8`, same as the `alloca`. This
is not expected, since toc-data symbol has the same alignment as toc
entry and should not be increased during optimizations.
---------
Co-authored-by: Sean Fertile <sd.fertile at gmail.com>
Co-authored-by: Eli Friedman <efriedma at quicinc.com>
Added:
Modified:
llvm/docs/LangRef.rst
llvm/lib/IR/Globals.cpp
llvm/test/CodeGen/PowerPC/tocdata-firm-alignment.ll
Removed:
################################################################################
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 492bfd546cf72..5a1535cb782fb 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -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]
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index 6f071847bb58a..3cc29ea8a340d 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -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;
}
diff --git a/llvm/test/CodeGen/PowerPC/tocdata-firm-alignment.ll b/llvm/test/CodeGen/PowerPC/tocdata-firm-alignment.ll
index c982713d4f8d3..4ecec36bc977a 100644
--- a/llvm/test/CodeGen/PowerPC/tocdata-firm-alignment.ll
+++ b/llvm/test/CodeGen/PowerPC/tocdata-firm-alignment.ll
@@ -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 {
More information about the llvm-commits
mailing list