Index: lib/MC/MCAssembler.cpp =================================================================== --- lib/MC/MCAssembler.cpp +++ lib/MC/MCAssembler.cpp @@ -256,7 +256,7 @@ else { // EndOfFragment > BundleSize return 2 * BundleSize - EndOfFragment; } - } else if (EndOfFragment > BundleSize) + } else if (OffsetInBundle > 0 && EndOfFragment > BundleSize) return BundleSize - OffsetInBundle; else return 0; @@ -586,15 +586,15 @@ // // When the -mc-relax-all flag is used, we optimize bundling by writting the // bundle padding directly into fragments when the instructions are emitted - // inside the streamer. + // inside the streamer. However, we still need to ensure that fragments are + // bundle aligned. // - if (Assembler.isBundlingEnabled() && !Assembler.getRelaxAll() && - F->hasInstructions()) { + if (Assembler.isBundlingEnabled() && F->hasInstructions()) { assert(isa(F) && "Only MCEncodedFragment implementations have instructions"); uint64_t FSize = Assembler.computeFragmentSize(*this, *F); - if (FSize > Assembler.getBundleAlignSize()) + if (!Assembler.getRelaxAll() && FSize > Assembler.getBundleAlignSize()) report_fatal_error("Fragment can't be larger than a bundle size"); uint64_t RequiredBundlePadding = computeBundlePadding(Assembler, F, Index: test/MC/X86/AlignedBundling/misaligned-bundle-group.s =================================================================== --- /dev/null +++ test/MC/X86/AlignedBundling/misaligned-bundle-group.s @@ -0,0 +1,19 @@ +# RUN: llvm-mc -filetype=obj -triple i686-pc-linux-gnu %s -o - \ +# RUN: | llvm-objdump -disassemble -no-show-raw-insn - | FileCheck -check-prefix=CHECK -check-prefix=CHECK-OPT %s +# RUN: llvm-mc -filetype=obj -triple i686-pc-linux-gnu -mc-relax-all %s -o - \ +# RUN: | llvm-objdump -disassemble -no-show-raw-insn - | FileCheck -check-prefix=CHECK -check-prefix=CHECK-RELAX %s + + .bundle_align_mode 5 + .text + hlt + .align 16 + .bundle_lock align_to_end +# CHECK: 1: nopw %cs:(%eax,%eax) +# CHECK-OPT: 10: nopw (%eax,%eax) +# CHECK-RELAX 10: nopw %cs:(%eax,%eax) +# CHECK-RELAX: 1f: nop +# CHECK-RELAX: 20: nopw %cs:(%eax,%eax) +# CHECK-RELAX: 2f: nopw %cs:(%eax,%eax) + movl $0x1, (%esp) + .bundle_unlock + movl $0x2, (%esp) Index: test/MC/X86/AlignedBundling/misaligned-bundle.s =================================================================== --- /dev/null +++ test/MC/X86/AlignedBundling/misaligned-bundle.s @@ -0,0 +1,23 @@ +# RUN: llvm-mc -filetype=obj -triple i686-pc-linux-gnu %s -o - \ +# RUN: | llvm-objdump -disassemble -no-show-raw-insn - | FileCheck -check-prefix=CHECK -check-prefix=CHECK-OPT %s +# RUN: llvm-mc -filetype=obj -triple i686-pc-linux-gnu -mc-relax-all %s -o - \ +# RUN: | llvm-objdump -disassemble -no-show-raw-insn - | FileCheck -check-prefix=CHECK -check-prefix=CHECK-RELAX %s + + .bundle_align_mode 5 + .text + hlt + .align 16 +# CHECK: 1: nopw %cs:(%eax,%eax) +# CHECK-RELAX: 10: nopw %cs:(%eax,%eax) +# CHECK-RELAX: 1f: nop + movl $0x1, (%esp) + movl $0x1, (%esp) +# CHECK-OPT: 1e: nop + movl $0x2, 0x1(%esp) + movl $0x2, 0x1(%esp) +# CHECK-RELAX: 3e: nop + movl $0x2, 0x1(%esp) + movl $0x2, (%esp) +# CHECK-OPT: 3f: nop + movl $0x3, (%esp) + movl $0x3, (%esp)