[llvm] 0d3149f - [MC][X86] Disable branch align in non-text section

Shengchen Kan via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 17 23:41:45 PDT 2020


Author: Shengchen Kan
Date: 2020-04-18T14:41:25+08:00
New Revision: 0d3149f43173967d6f4e4c5c904a05e1022071d4

URL: https://github.com/llvm/llvm-project/commit/0d3149f43173967d6f4e4c5c904a05e1022071d4
DIFF: https://github.com/llvm/llvm-project/commit/0d3149f43173967d6f4e4c5c904a05e1022071d4.diff

LOG: [MC][X86] Disable branch align in non-text section

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

Added: 
    llvm/test/MC/X86/align-branch-section-type.s

Modified: 
    llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
index 356eb0a7be0f..a7ed81dee6d2 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
@@ -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;

diff  --git a/llvm/test/MC/X86/align-branch-section-type.s b/llvm/test/MC/X86/align-branch-section-type.s
new file mode 100644
index 000000000000..7a5c10b83d9e
--- /dev/null
+++ b/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


        


More information about the llvm-commits mailing list