diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -3655,11 +3655,6 @@ } } - // Emit an alignment directive for this block, if needed. - const Align Alignment = MBB.getAlignment(); - if (Alignment != Align(1)) - emitAlignment(Alignment, nullptr, MBB.getMaxBytesForAlignment()); - // Switch to a new section if this basic block must begin a section. The // entry block is always placed in the function section and is handled // separately. @@ -3670,6 +3665,11 @@ CurrentSectionBeginSym = MBB.getSymbol(); } + // Emit an alignment directive for this block, if needed. + const Align Alignment = MBB.getAlignment(); + if (Alignment != Align(1)) + emitAlignment(Alignment, nullptr, MBB.getMaxBytesForAlignment()); + // If the block has its address taken, emit any labels that were used to // reference the block. It is possible that there is more than one label // here, because multiple LLVM BB's may have been RAUW'd to this block after diff --git a/llvm/test/CodeGen/X86/align-basic-block-sections.ll b/llvm/test/CodeGen/X86/align-basic-block-sections.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/X86/align-basic-block-sections.ll @@ -0,0 +1,66 @@ +; RUN: llc < %s -march=x86-64 --basic-block-sections=all --unique-basic-block-section-names | FileCheck %s --check-prefix=ASM +; RUN: llc < %s -march=x86-64 --basic-block-sections=all --unique-basic-block-section-names -filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=OBJ + +define void @maxArray(double* %x, double* %y) { +; ASM-LABEL: maxArray: +; ASM: .section .text.maxArray.maxArray.__part.2,"ax",@progbits +; ASM-NEXT: maxArray.__part.2: +; ASM-NEXT: .cfi_startproc +; ASM-NEXT: .cfi_def_cfa %rsp, 8 +; ASM-NEXT: xorl %eax, %eax +; ASM-NEXT: jmp maxArray.__part.3 +; ASM-NEXT: .LBB_END0_2: +; ASM-NEXT: .size maxArray.__part.2, .LBB_END0_2-maxArray.__part.2 +; ASM-NEXT: .cfi_endproc +; ASM-NEXT: .section .text.maxArray.maxArray.__part.3,"ax",@progbits +; ASM-NEXT: .p2align 4, 0x90 +; ASM-NEXT: maxArray.__part.3: # %vector.body +; ASM-NEXT: # =>This Inner Loop Header: Depth=1 + +entry: + %x_addr = ptrtoint double* %x to i64 + %y_addr = ptrtoint double* %y to i64 + %nonull = icmp eq i64 %y_addr, %x_addr + br i1 %nonull, label %preheader, label %vector.body +preheader: + %random_idx = sub i64 %x_addr, 20 + br label %vector.body +vector.body: + %index = phi i64 [ %random_idx, %preheader ], [ 0, %entry ], [ %index.next, %vector.body ] + %gepx = getelementptr inbounds double, double* %x, i64 %index + %gepy = getelementptr inbounds double, double* %y, i64 %index + %xptr = bitcast double* %gepx to <2 x double>* + %yptr = bitcast double* %gepy to <2 x double>* + %xval = load <2 x double>, <2 x double>* %xptr, align 8 + %yval = load <2 x double>, <2 x double>* %yptr, align 8 + %cmp = fcmp ogt <2 x double> %yval, %xval + %max = select <2 x i1> %cmp, <2 x double> %yval, <2 x double> %xval + %xptr_again = bitcast double* %gepx to <2 x double>* + store <2 x double> %max, <2 x double>* %xptr_again, align 8 + %index.next = add i64 %index, 2 + %done = icmp eq i64 %index.next, %y_addr + br i1 %done, label %exit, label %vector.body + +exit: + ret void +} + +; OBJ-LABEL: Sections: +; OBJ-LABEL: - Name: .text +; OBJ-LABEL: Type: SHT_PROGBITS +; OBJ-LABEL: Flags: [ SHF_ALLOC, SHF_EXECINSTR ] +; OBJ-LABEL: AddressAlign: 0x4 +; OBJ-LABEL: - Name: .text.maxArray +; OBJ-LABEL: Type: SHT_PROGBITS +; OBJ-LABEL: Flags: [ SHF_ALLOC, SHF_EXECINSTR ] +; OBJ-LABEL: AddressAlign: 0x10 +; OBJ-LABEL: Content: 4839FE0F8500000000E900000000 +; OBJ-LABEL: - Name: .text.maxArray.maxArray.__part.1 +; OBJ-LABEL: Type: SHT_PROGBITS +; OBJ-LABEL: Flags: [ SHF_ALLOC, SHF_EXECINSTR ] +; OBJ-LABEL: AddressAlign: 0x1 +; OBJ-LABEL: Content: 31C0E900000000 +; OBJ-LABEL: - Name: .text.maxArray.maxArray.__part.3 +; OBJ-LABEL: Type: SHT_PROGBITS +; OBJ-LABEL: Flags: [ SHF_ALLOC, SHF_EXECINSTR ] +; OBJ-LABEL: AddressAlign: 0x10