-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
@llvm/pr-subscribers-backend-powerpc @llvm/pr-subscribers-llvm-ir Author: Kai Luo (bzEq) ChangesCurrently, the alignment of toc-data symbol might be changed during instcombine
The Full diff: https://github.com/llvm/llvm-project/pull/94593.diff 2 Files Affected:
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index 6f071847bb58..2943a2aa0cf6 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -335,6 +335,14 @@ bool GlobalObject::canIncreaseAlignment() const {
if (isELF && !isDSOLocal())
return false;
+ bool isXCOFF =
+ (!Parent || Triple(Parent->getTargetTriple()).isOSBinFormatXCOFF());
+ if (isXCOFF)
+ if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
+ // GV with toc-data attribute is put in the region same as toc entry.
+ // Its alignment should be the same as toc entry.
+ return !GV->hasAttribute("toc-data");
+
return true;
}
diff --git a/llvm/test/CodeGen/PowerPC/tocdata-firm-alignment.ll b/llvm/test/CodeGen/PowerPC/tocdata-firm-alignment.ll
index c982713d4f8d..4ecec36bc977 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 {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better suited to place the test in Transforms/InferAlignment/
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks like a place for InferAlignmentPass
.
Co-authored-by: Sean Fertile <[email protected]>
✅ With the latest revision this PR passed the C/C++ code formatter. |
Why does AIX have this requirement? ppc64 ELFv2 ABI can increase the alignment without any issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the perspective of the IR, this is the correct way to implement this restriction. (toc-data should be documented in LangRef, though.) I won't try to dive into the XCOFF side of this.
I tend to believe it's implementation's limitation, see
|
IIUC, AIX has limited TOC region especially for small code model and TOC region is created by linker(i.e., compiler can not fully control the layout of the TOC entries), so to avoid wasting of TOC entries, guarding alignment of the TOC data symbols be same with normal toc entries is necessary.
If a is a toc-data symbol and we change its alignment to 16 in the assembly ( 2^16 is the size of the TOC region for small code model), compiling the modified assembly will make AIX linker emit TOC overflow error. |
Thanks for the example. I have also tried
AIX has the limited R_TOC relocation, similar to R_PPC64_TOC16_DS emitted by ELFv1 ELFv2 with -mcmodel=small. |
llvm/lib/IR/Globals.cpp
Outdated
(!Parent || Triple(Parent->getTargetTriple()).isOSBinFormatXCOFF()); | ||
if (isXCOFF) | ||
if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this)) | ||
// GV with toc-data attribute is defined in a TOC entry which has a fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment can be lifted before isXCOFF
. It seems not correct.
The alignment is not increased to mitigate TOC size overflow.
|
I'll leave doc change also in the same PR. |
Ping @efriedma-quic , could you please review the doc change? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New documentation looks fine. One minor suggestion for the code; otherwise LGTM
Co-authored-by: Eli Friedman <[email protected]>
Currently, the alignment of toc-data symbol might be changed during instcombine
The
alloca
is created withPrefAlign
which is 8 and after IC, the alignment of@global
is enforced into8
, same as thealloca
. This is not expected, since toc-data symbol has the same alignment as toc entry and should not be increased during optimizations.