Skip to content

Commit 117921e

Browse files
Kai Luomandlebugefriedma-quic
authored
[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 <[email protected]> Co-authored-by: Eli Friedman <[email protected]>
1 parent d68eb5b commit 117921e

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

llvm/docs/LangRef.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,10 @@ doesn't). These kinds of structs (we may call them homogeneous scalable vector
812812
structs) are considered sized and can be used in loads, stores, allocas, but
813813
not GEPs.
814814

815+
Globals with ``toc-data`` attribute set are stored in TOC of XCOFF. Their
816+
alignments are not larger than that of a TOC entry. Optimizations should not
817+
increase their alignments to mitigate TOC overflow.
818+
815819
Syntax::
816820

817821
@<GlobalVarName> = [Linkage] [PreemptionSpecifier] [Visibility]

llvm/lib/IR/Globals.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,16 @@ bool GlobalObject::canIncreaseAlignment() const {
335335
if (isELF && !isDSOLocal())
336336
return false;
337337

338+
// GV with toc-data attribute is defined in a TOC entry. To mitigate TOC
339+
// overflow, the alignment of such symbol should not be increased. Otherwise,
340+
// padding is needed thus more TOC entries are wasted.
341+
bool isXCOFF =
342+
(!Parent || Triple(Parent->getTargetTriple()).isOSBinFormatXCOFF());
343+
if (isXCOFF)
344+
if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
345+
if (GV->hasAttribute("toc-data"))
346+
return false;
347+
338348
return true;
339349
}
340350

llvm/test/CodeGen/PowerPC/tocdata-firm-alignment.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ target triple = "powerpc-ibm-aix7.2.0.0"
55

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

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

1111
define void @baz() #1 {

0 commit comments

Comments
 (0)