diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp --- a/llvm/lib/MC/MCObjectStreamer.cpp +++ b/llvm/lib/MC/MCObjectStreamer.cpp @@ -399,8 +399,7 @@ // fragment. if (Assembler.getRelaxAll() || (Assembler.isBundlingEnabled() && Sec->isBundleLocked())) { - MCInst Relaxed; - getAssembler().getBackend().relaxInstruction(Inst, STI, Relaxed); + MCInst Relaxed = Inst; while (getAssembler().getBackend().mayNeedRelaxation(Relaxed, STI)) getAssembler().getBackend().relaxInstruction(Relaxed, STI, Relaxed); EmitInstToData(Relaxed, STI); diff --git a/llvm/test/MC/X86/align-branch-64-relax-all.s b/llvm/test/MC/X86/align-branch-64-relax-all.s --- a/llvm/test/MC/X86/align-branch-64-relax-all.s +++ b/llvm/test/MC/X86/align-branch-64-relax-all.s @@ -1,4 +1,5 @@ # RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu --x86-align-branch-boundary=32 --x86-align-branch=fused+jcc --mc-relax-all %s | llvm-objdump -d --no-show-raw-insn - | FileCheck %s + # RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu --x86-align-branch-boundary=32 --x86-align-branch=fused+jcc --x86-pad-max-prefix-size=5 --mc-relax-all %s | llvm-objdump -d --no-show-raw-insn - | FileCheck %s # Check instructions can be aligned correctly along with option --mc-relax-all