Skip to content

Commit 9878ef3

Browse files
authored
CodeGen: Respect function align attribute if less than preferred alignment.
Reviewers: arsenm, efriedma-quic Reviewed By: arsenm Pull Request: #149444
1 parent c5f0c4a commit 9878ef3

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

llvm/lib/CodeGen/MachineFunction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,8 @@ void MachineFunction::init() {
211211
ConstantPool = new (Allocator) MachineConstantPool(getDataLayout());
212212
Alignment = STI->getTargetLowering()->getMinFunctionAlignment();
213213

214-
// FIXME: Shouldn't use pref alignment if explicit alignment is set on F.
215214
// FIXME: Use Function::hasOptSize().
216-
if (!F.hasFnAttribute(Attribute::OptimizeForSize))
215+
if (!F.getAlign() && !F.hasFnAttribute(Attribute::OptimizeForSize))
217216
Alignment = std::max(Alignment,
218217
STI->getTargetLowering()->getPrefFunctionAlignment());
219218

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: llc -function-sections < %s | FileCheck %s
2+
3+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
4+
target triple = "x86_64-unknown-linux-gnu"
5+
6+
; CHECK: .section .text.f1
7+
; CHECK-NOT: .p2align
8+
; CHECK: f1:
9+
define void @f1() align 1 {
10+
ret void
11+
}
12+
13+
; CHECK: .section .text.f2
14+
; CHECK-NEXT: .globl f2
15+
; CHECK-NEXT: .p2align 1
16+
define void @f2() align 2 {
17+
ret void
18+
}

0 commit comments

Comments
 (0)