diff --git a/lld/test/ELF/lto/linker-script-symbols-ipo.ll b/lld/test/ELF/lto/linker-script-symbols-ipo.ll index 414ee4080bee0..39996cbfa28db 100644 --- a/lld/test/ELF/lto/linker-script-symbols-ipo.ll +++ b/lld/test/ELF/lto/linker-script-symbols-ipo.ll @@ -18,7 +18,7 @@ ; NOIPO: : ; NOIPO-NEXT: movl $2, %eax ; NOIPO: <_start>: -; NOIPO-NEXT: jmp 0x201160 +; NOIPO-NEXT: jmp 0x201158 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 0bc76590d3208..361c898c629d4 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -977,8 +977,20 @@ void AsmPrinter::emitFunctionHeader() { emitVisibility(CurrentFnSym, F.getVisibility()); emitLinkage(&F, CurrentFnSym); - if (MAI->hasFunctionAlignment()) - emitAlignment(MF->getPreferredAlignment(), &F); + if (MAI->hasFunctionAlignment()) { + // The preferred alignment directive will not have the intended effect + // unless function sections are enabled. + if (MAI->useIntegratedAssembler() && MAI->hasPreferredAlignment() && + TM.getFunctionSections()) { + Align Alignment = MF->getAlignment(); + Align PrefAlignment = MF->getPreferredAlignment(); + emitAlignment(Alignment, &F); + if (Alignment != PrefAlignment) + OutStreamer->emitPrefAlign(PrefAlignment); + } else { + emitAlignment(MF->getPreferredAlignment(), &F); + } + } if (MAI->hasDotTypeDotSizeDirective()) OutStreamer->emitSymbolAttribute(CurrentFnSym, MCSA_ELF_TypeFunction); diff --git a/llvm/test/CodeGen/X86/prefalign.ll b/llvm/test/CodeGen/X86/prefalign.ll new file mode 100644 index 0000000000000..9a775bc328c60 --- /dev/null +++ b/llvm/test/CodeGen/X86/prefalign.ll @@ -0,0 +1,27 @@ +; RUN: llc < %s | FileCheck --check-prefixes=CHECK,NOFS %s +; RUN: llc -function-sections < %s | FileCheck --check-prefixes=CHECK,FS %s + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; CHECK: .globl f1 +; NOFS-NEXT: .p2align 4 +; FS-NEXT: .prefalign 16 +define void @f1() { + ret void +} + +; CHECK: .globl f2 +; CHECK-NOT: .prefalign +; CHECK-NOT: .p2align +define void @f2() prefalign 1 { + ret void +} + +; CHECK: .globl f3 +; NOFS-NEXT: .p2align 2 +; FS-NEXT: .p2align 1 +; FS-NEXT: .prefalign 4 +define void @f3() align 2 prefalign 4 { + ret void +} diff --git a/llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll b/llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll index 1aa0f65ce3367..b3c2ac36ec08d 100644 --- a/llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll +++ b/llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll @@ -127,7 +127,7 @@ entry: ; CHECK-SEC-ELF: [Nr] Name Type {{.*}} ES Flg Lk Inf Al ; CHECK-SEC-ELF: [ 3] .text.foo PROGBITS {{.*}} 00 AX 0 0 16 ; CHECK-SEC-ELF: [ 5] .text.foo2 PROGBITS {{.*}} 00 AX 0 0 16 -; CHECK-SEC-ELF: [ 8] .text.foo3 PROGBITS {{.*}} 00 AXG 0 0 16 +; CHECK-SEC-ELF: [ 8] .text.foo3 PROGBITS {{.*}} 00 AXG 0 0 1 ; CHECK-SEC-ELF-COUNT-3: .pseudo_probe_desc PROGBITS ; CHECK-SEC-ELF: .pseudo_probe PROGBITS {{.*}} 00 L 3 0 1 ; CHECK-SEC-ELF-NEXT: .pseudo_probe PROGBITS {{.*}} 00 L 5 0 1 @@ -154,7 +154,7 @@ entry: ; CHECK-SEC2-ELF: [Nr] Name Type {{.*}} ES Flg Lk Inf Al ; CHECK-SEC2-ELF: [ 3] .text PROGBITS {{.*}} 00 AX 0 0 16 ; CHECK-SEC2-ELF: [ 5] .text PROGBITS {{.*}} 00 AX 0 0 16 -; CHECK-SEC2-ELF: [ 8] .text PROGBITS {{.*}} 00 AXG 0 0 16 +; CHECK-SEC2-ELF: [ 8] .text PROGBITS {{.*}} 00 AXG 0 0 1 ; CHECK-SEC2-ELF-COUNT-3: .pseudo_probe_desc PROGBITS ; CHECK-SEC2-ELF: .pseudo_probe PROGBITS {{.*}} 00 L 3 0 1 ; CHECK-SEC2-ELF-NEXT: .pseudo_probe PROGBITS {{.*}} 00 L 5 0 1