Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,16 @@ void X86AsmBackend::emitInstructionBegin(MCObjectStreamer &OS,
if (!CanPadInst)
return;

if (PendingBA && PendingBA->getNext() == OS.getCurrentFragment()) {
if (PendingBA) {
auto *NextFragment = PendingBA->getNext();
assert(NextFragment && "NextFragment should not be null");
if (NextFragment == OS.getCurrentFragment())
return;
// We eagerly create an empty fragment when inserting a fragment
// with a variable-size tail.
if (NextFragment->getNext() == OS.getCurrentFragment())
return;

// Macro fusion actually happens and there is no other fragment inserted
// after the previous instruction.
//
Expand Down
20 changes: 19 additions & 1 deletion llvm/test/MC/X86/align-branch-fused.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# RUN: llvm-mc -filetype=obj -triple x86_64 --x86-align-branch-boundary=32 --x86-align-branch=fused+jcc %s | llvm-objdump -d --no-show-raw-insn - | FileCheck %s
# RUN: rm -rf %t && split-file %s %t && cd %t
# RUN: llvm-mc -filetype=obj -triple x86_64 --x86-align-branch-boundary=32 --x86-align-branch=fused+jcc foo.s | llvm-objdump -d --no-show-raw-insn - | FileCheck foo.s
# RUN: llvm-mc -filetype=obj -triple x86_64 --x86-align-branch-boundary=32 --x86-align-branch=fused+jcc -x86-pad-max-prefix-size=1 bar.s | llvm-objdump -d --no-show-raw-insn - | FileCheck bar.s

# Exercise cases where fused instructions need to be aligned.

#--- foo.s
.text
.globl foo
foo:
Expand Down Expand Up @@ -40,3 +43,18 @@ foo:
cmp %rax, %rbp
jne foo
int3

# Exercise the case where fused instructions need to be aligned,
# ensuring fusion is not broken by a NOP

#--- bar.s
.text
.globl bar
bar:
.nops 27
# CHECK: 20: testq %rcx, %rcx
# CHECK: 23: je
testq %rcx, %rcx
je .EXIT
.EXIT:
ret