[llvm] [PowerPC] Alignment of toc-data symbol should not be increased during optimizations (PR #94593)
Kai Luo via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 6 07:18:08 PDT 2024
https://github.com/bzEq updated https://github.com/llvm/llvm-project/pull/94593
>From a499354b0dd9cc987fd9d0a9c6cd270e1a32bb66 Mon Sep 17 00:00:00 2001
From: Kai Luo <lkail at cn.ibm.com>
Date: Thu, 6 Jun 2024 09:07:13 +0000
Subject: [PATCH 1/2] Fix
---
llvm/lib/IR/Globals.cpp | 8 ++++++++
llvm/test/CodeGen/PowerPC/tocdata-firm-alignment.ll | 2 +-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index 6f071847bb58a..2943a2aa0cf63 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 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 {
>From 315e42bc7cfea8380a362dbb19b992d9ebd08fcd Mon Sep 17 00:00:00 2001
From: Kai Luo <gluokai at gmail.com>
Date: Thu, 6 Jun 2024 22:18:00 +0800
Subject: [PATCH 2/2] Adjust comment
Co-authored-by: Sean Fertile <sd.fertile at gmail.com>
---
llvm/lib/IR/Globals.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index 2943a2aa0cf63..1d4116a9c4f9b 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -339,7 +339,8 @@ bool GlobalObject::canIncreaseAlignment() const {
(!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.
+ // GV with toc-data attribute is defined in a TOC entry which
+ // has a fixed alignment and cannot be arbitrarily increased.
// Its alignment should be the same as toc entry.
return !GV->hasAttribute("toc-data");
More information about the llvm-commits
mailing list