[llvm] [PowerPC] Alignment of toc-data symbol should not be changed during optimization (PR #94593)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 6 02:06:14 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Kai Luo (bzEq)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/94593.diff
2 Files Affected:
- (modified) llvm/lib/IR/Globals.cpp (+8)
- (modified) llvm/test/CodeGen/PowerPC/tocdata-firm-alignment.ll (+1-1)
``````````diff
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 {
``````````
</details>
https://github.com/llvm/llvm-project/pull/94593
More information about the llvm-commits
mailing list