[X86][MC] Make -x86-pad-max-prefix-size compatible with --mc-relax-all

Summary: We allow non-relaxable instructions emitted into relaxable Fragment when we prefix padding branch. So we need to check if the instruction need relaxation before relaxing it.  Without this patch, it currently triggers a `report_fatal_error` in `llvm::MCAsmBackend::relaxInstruction` when we prefix padding branch along with `--mc-relax-all`.

Reviewers: LuoYuanke, reames, MaskRay

Reviewed By: MaskRay

Subscribers: MaskRay, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77851
This commit is contained in:
Shengchen Kan 2020-04-10 18:37:24 +08:00
parent c610807afe
commit 5d73f79c54
2 changed files with 2 additions and 2 deletions

View File

@ -399,8 +399,7 @@ void MCObjectStreamer::emitInstructionImpl(const MCInst &Inst,
// fragment. // fragment.
if (Assembler.getRelaxAll() || if (Assembler.getRelaxAll() ||
(Assembler.isBundlingEnabled() && Sec->isBundleLocked())) { (Assembler.isBundlingEnabled() && Sec->isBundleLocked())) {
MCInst Relaxed; MCInst Relaxed = Inst;
getAssembler().getBackend().relaxInstruction(Inst, STI, Relaxed);
while (getAssembler().getBackend().mayNeedRelaxation(Relaxed, STI)) while (getAssembler().getBackend().mayNeedRelaxation(Relaxed, STI))
getAssembler().getBackend().relaxInstruction(Relaxed, STI, Relaxed); getAssembler().getBackend().relaxInstruction(Relaxed, STI, Relaxed);
EmitInstToData(Relaxed, STI); EmitInstToData(Relaxed, STI);

View File

@ -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 --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 # Check instructions can be aligned correctly along with option --mc-relax-all