[llvm] [CodeGen] Don't allow function alignment less than the target's minimum (PR #90415)
Doug Wyatt via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 29 09:56:02 PDT 2024
https://github.com/dougsonos updated https://github.com/llvm/llvm-project/pull/90415
>From 527872f0e53a7f2a71023b063322258272fd4e0f Mon Sep 17 00:00:00 2001
From: Doug Wyatt <dwyatt at apple.com>
Date: Thu, 25 Apr 2024 13:25:05 -0700
Subject: [PATCH 1/2] [llvm codegen] In AsmPrinter::emitAlignment, don't allow
the possibly smaller alignment of the GlobalObject to reduce a function's
alignment below the target's minimum function alignment. (#90358)
---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 721d144d7f4c67..c29f9aa97f0165 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -3147,9 +3147,17 @@ void AsmPrinter::emitAlignment(Align Alignment, const GlobalObject *GV,
if (getCurrentSection()->getKind().isText()) {
const MCSubtargetInfo *STI = nullptr;
- if (this->MF)
- STI = &getSubtargetInfo();
- else
+ if (this->MF) {
+ // Don't allow the possibly smaller alignment of the GV
+ // (e.g. 2 for a C++ method) to reduce a function's alignment
+ // below the target's minimum function alignment. (#90358)
+ const TargetSubtargetInfo *TSI = &MF->getSubtarget();
+ const Align MinAlign =
+ TSI->getTargetLowering()->getMinFunctionAlignment();
+ if (Alignment < MinAlign)
+ Alignment = MinAlign;
+ STI = TSI;
+ } else
STI = TM.getMCSubtargetInfo();
OutStreamer->emitCodeAlignment(Alignment, STI, MaxBytesToEmit);
} else
>From 33bcaecf382172a4a56096e18e420ff3dc0a74d9 Mon Sep 17 00:00:00 2001
From: Doug Wyatt <dwyatt at apple.com>
Date: Mon, 29 Apr 2024 09:55:19 -0700
Subject: [PATCH 2/2] Add test
---
llvm/test/CodeGen/AArch64/func-alignment.ll | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
create mode 100644 llvm/test/CodeGen/AArch64/func-alignment.ll
diff --git a/llvm/test/CodeGen/AArch64/func-alignment.ll b/llvm/test/CodeGen/AArch64/func-alignment.ll
new file mode 100644
index 00000000000000..0860578065bcd1
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/func-alignment.ll
@@ -0,0 +1,19 @@
+; RUN: llc -mtriple=aarch64 -O0 -fast-isel < %s | FileCheck %s
+
+; Verify that Clang's C++ ABI alignment for functions of 2 does not
+; result in underaligned functions when they are in special sections.
+; (#90415)
+
+define void @noSection() align 2 {
+; CHECK: .p2align 2
+entry:
+ ret void
+}
+
+define void @withSection() section "__TEXT,__foo,regular,pure_instructions" align 2 {
+; CHECK: .p2align 2
+entry:
+ ret void
+}
+
+
More information about the llvm-commits
mailing list