[llvm-branch-commits] [llvm] a048ce1 - [X86] Default to -x86-pad-for-align=false to drop assembler difference with or w/o -g
Fangrui Song via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Jan 16 16:44:09 PST 2021
Author: Fangrui Song
Date: 2021-01-16T16:39:54-08:00
New Revision: a048ce13e32daa255d26533c00da8abd0b67e819
URL: https://github.com/llvm/llvm-project/commit/a048ce13e32daa255d26533c00da8abd0b67e819
DIFF: https://github.com/llvm/llvm-project/commit/a048ce13e32daa255d26533c00da8abd0b67e819.diff
LOG: [X86] Default to -x86-pad-for-align=false to drop assembler difference with or w/o -g
Fix PR48742: the D75203 assembler optimization locates MCRelaxableFragment's
within two MCSymbol's and relaxes some MCRelaxableFragment's to reduce the size
of a MCAlignFragment. A -g build has more MCSymbol's and therefore may have
different assembler output (e.g. a MCRelaxableFragment (jmp) may have 5 bytes
with -O1 while 2 bytes with -O1 -g).
`.p2align 4, 0x90` is common due to loops. For a larger program, with a
lot of temporary labels, the assembly output difference is somewhat
destined. The cost seems to overweigh the benefits so we default to
-x86-pad-for-align=false until the heuristic is improved.
Reviewed By: skan
Differential Revision: https://reviews.llvm.org/D94542
Added:
Modified:
llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
llvm/test/MC/X86/align-via-padding-corner.s
llvm/test/MC/X86/align-via-padding.s
llvm/test/MC/X86/align-via-relaxation.s
llvm/test/MC/X86/prefix-padding-32.s
llvm/test/MC/X86/prefix-padding-64.s
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
index a7d71bd35d29..95012a148d83 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
@@ -109,7 +109,7 @@ cl::opt<unsigned> X86PadMaxPrefixSize(
cl::desc("Maximum number of prefixes to use for padding"));
cl::opt<bool> X86PadForAlign(
- "x86-pad-for-align", cl::init(true), cl::Hidden,
+ "x86-pad-for-align", cl::init(false), cl::Hidden,
cl::desc("Pad previous instructions to implement align directives"));
cl::opt<bool> X86PadForBranchAlign(
@@ -957,6 +957,9 @@ void X86AsmBackend::finishLayout(MCAssembler const &Asm,
if (!X86PadForAlign && !X86PadForBranchAlign)
return;
+ // The processed regions are delimitered by LabeledFragments. -g may have more
+ // MCSymbols and therefore
diff erent relaxation results. X86PadForAlign is
+ // disabled by default to eliminate the -g vs non -g
diff erence.
DenseSet<MCFragment *> LabeledFragments;
for (const MCSymbol &S : Asm.symbols())
LabeledFragments.insert(S.getFragment(false));
diff --git a/llvm/test/MC/X86/align-via-padding-corner.s b/llvm/test/MC/X86/align-via-padding-corner.s
index cc13ff7eed7f..6b8e02d198a5 100644
--- a/llvm/test/MC/X86/align-via-padding-corner.s
+++ b/llvm/test/MC/X86/align-via-padding-corner.s
@@ -1,4 +1,4 @@
- # RUN: llvm-mc -mcpu=skylake -filetype=obj -triple x86_64-pc-linux-gnu %s -x86-pad-max-prefix-size=5 | llvm-objdump -d - | FileCheck %s
+ # RUN: llvm-mc -mcpu=skylake -filetype=obj -triple x86_64-pc-linux-gnu %s -x86-pad-max-prefix-size=5 -x86-pad-for-align=1 | llvm-objdump -d - | FileCheck %s
# The first test check the correctness cornercase - can't add prefixes on a
diff --git a/llvm/test/MC/X86/align-via-padding.s b/llvm/test/MC/X86/align-via-padding.s
index d5d86da6ddca..32495fe4a3ae 100644
--- a/llvm/test/MC/X86/align-via-padding.s
+++ b/llvm/test/MC/X86/align-via-padding.s
@@ -1,4 +1,4 @@
-# RUN: llvm-mc -mcpu=skylake -filetype=obj -triple x86_64-pc-linux-gnu %s -x86-pad-max-prefix-size=5 | llvm-objdump -d --section=.text - | FileCheck %s
+# RUN: llvm-mc -mcpu=skylake -filetype=obj -triple x86_64-pc-linux-gnu %s -x86-pad-max-prefix-size=5 -x86-pad-for-align=1 | llvm-objdump -d - | FileCheck %s
# This test file highlights the interactions between prefix padding and
# relaxation padding.
diff --git a/llvm/test/MC/X86/align-via-relaxation.s b/llvm/test/MC/X86/align-via-relaxation.s
index d768232655b7..394efaf6d75b 100644
--- a/llvm/test/MC/X86/align-via-relaxation.s
+++ b/llvm/test/MC/X86/align-via-relaxation.s
@@ -1,4 +1,5 @@
-# RUN: llvm-mc -mcpu=skylake -filetype=obj -triple x86_64-pc-linux-gnu -x86-pad-max-prefix-size=0 %s | llvm-objdump -d --section=.text - | FileCheck %s
+# RUN: llvm-mc -mcpu=skylake -filetype=obj -triple x86_64-pc-linux-gnu -x86-pad-max-prefix-size=0 %s | llvm-objdump -d - | FileCheck %s --check-prefix=NOPAD
+# RUN: llvm-mc -mcpu=skylake -filetype=obj -triple x86_64-pc-linux-gnu -x86-pad-max-prefix-size=0 -x86-pad-for-align=1 %s | llvm-objdump -d - | FileCheck %s
# This test exercises only the padding via relaxation logic. The interaction
# etween prefix padding and relaxation logic can be seen in align-via-padding.s
@@ -6,6 +7,19 @@
.file "test.c"
.text
.section .text
+
+# NOPAD-LABEL: <.text>:
+# NOPAD-NEXT: 0: eb 1f jmp 0x21 <foo>
+# NOPAD-NEXT: 2: eb 1d jmp 0x21 <foo>
+# NOPAD-NEXT: 4: eb 1b jmp 0x21 <foo>
+# NOPAD-NEXT: 6: eb 19 jmp 0x21 <foo>
+# NOPAD-NEXT: 8: eb 17 jmp 0x21 <foo>
+# NOPAD-NEXT: a: eb 15 jmp 0x21 <foo>
+# NOPAD-NEXT: c: eb 13 jmp 0x21 <foo>
+# NOPAD-NEXT: e: 66 66 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 nopw %cs:(%rax,%rax)
+# NOPAD-NEXT: 1d: 0f 1f 00 nopl (%rax)
+# NOPAD-NEXT: 20: cc int3
+
# Demonstrate that we can relax instructions to provide padding, not
# just insert nops. jmps are being used for ease of demonstration.
# CHECK: .text
diff --git a/llvm/test/MC/X86/prefix-padding-32.s b/llvm/test/MC/X86/prefix-padding-32.s
index b975bd5783c0..380c705908d5 100644
--- a/llvm/test/MC/X86/prefix-padding-32.s
+++ b/llvm/test/MC/X86/prefix-padding-32.s
@@ -1,4 +1,4 @@
-# RUN: llvm-mc -filetype=obj -triple i386-pc-linux-gnu %s -x86-pad-max-prefix-size=15 | llvm-objdump -d --section=.text - | FileCheck %s
+# RUN: llvm-mc -filetype=obj -triple i386-pc-linux-gnu %s -x86-pad-max-prefix-size=15 -x86-pad-for-align=1 | llvm-objdump -d - | FileCheck %s
# Check prefix padding generation for all cases on 32 bit x86.
diff --git a/llvm/test/MC/X86/prefix-padding-64.s b/llvm/test/MC/X86/prefix-padding-64.s
index fcffc772d25b..7ba618d8f233 100644
--- a/llvm/test/MC/X86/prefix-padding-64.s
+++ b/llvm/test/MC/X86/prefix-padding-64.s
@@ -1,4 +1,4 @@
-# RUN: llvm-mc -mcpu=skylake -filetype=obj -triple x86_64-pc-linux-gnu %s -x86-pad-max-prefix-size=15 | llvm-objdump -d --section=.text - | FileCheck %s
+# RUN: llvm-mc -mcpu=skylake -filetype=obj -triple x86_64-pc-linux-gnu %s -x86-pad-max-prefix-size=15 -x86-pad-for-align=1 | llvm-objdump -d - | FileCheck %s
# Check prefix padding generation for all cases on 64 bit x86.
More information about the llvm-branch-commits
mailing list