Skip to content

Commit

Permalink
[MC][X86] Disable branch align in non-text section
Browse files Browse the repository at this point in the history
Summary:
The instruction in non-text section can not be executed, so they will not affect performance.
In addition, their encoding values are treated as data, so we should not touch them.

Reviewers: MaskRay, reames, LuoYuanke, jyknight

Reviewed By: MaskRay

Subscribers: annita.zhang, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77971
  • Loading branch information
KanRobert committed Apr 18, 2020
1 parent eef9cb1 commit 0d3149f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
Expand Up @@ -566,6 +566,10 @@ bool X86AsmBackend::canPadBranches(MCObjectStreamer &OS) const {
return false;
assert(allowAutoPadding() && "incorrect initialization!");

// We only pad in text section.
if (!OS.getCurrentSectionOnly()->getKind().isText())
return false;

// To be Done: Currently don't deal with Bundle cases.
if (OS.getAssembler().isBundlingEnabled())
return false;
Expand Down
18 changes: 18 additions & 0 deletions llvm/test/MC/X86/align-branch-section-type.s
@@ -0,0 +1,18 @@
# RUN: llvm-mc -filetype=obj -triple x86_64 --x86-align-branch-boundary=32 --x86-align-branch=ret %s | llvm-readobj -S | FileCheck %s

## Check we only pad in a text section

# CHECK-LABEL: Name: text
# CHECK: AddressAlignment: 32
.section text, "ax"
ret

# CHECK-LABEL: Name: excluded
# CHECK: AddressAlignment: 1
.section excluded, "e"
ret

# CHECK-LABEL: Name: tls
# CHECK: AddressAlignment: 1
.section tls, "awT"
ret

0 comments on commit 0d3149f

Please sign in to comment.