summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-09-23 13:26:50 -0700
committerH.J. Lu <hjl.tools@gmail.com>2017-09-24 14:50:06 -0700
commit28e556981bb0304d695eb4dfc1b7232919e5cdd6 (patch)
tree3e585af1fbdf1d3ac7aa5ce1078598a5d42689d5
parentc7c38fb150f8c6bbee3e010098f1dd88baa054e4 (diff)
downloadgcc-hjl/pr82267/gcc-7-branch.tar.gz
x32: Encode %esp as %rsp to avoid 0x67 prefixhjl/pr82267/gcc-7-branch
Since the upper 32 bits of stack register are always zero for x32, we can encode %esp as %rsp to avoid 0x67 prefix in address if there is no index or base register. Back port from mainline r253127. gcc/ 2017-09-24 Uros Bizjak <ubizjak@gmail.com> PR target/82267 * config/i386/i386.c (ix86_print_operand_address_as): Encode %esp as %rsp to avoid 0x67 prefix if there is no index or base register. gcc/testsuite/ 2017-09-24 H.J. Lu <hongjiu.lu@intel.com> PR target/82267 * gcc.target/i386/pr82267.c: New tests.
-rw-r--r--gcc/config/i386/i386.c8
-rw-r--r--gcc/testsuite/gcc.target/i386/pr82267.c14
2 files changed, 22 insertions, 0 deletions
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 4f036ba9e20..4cf981fe981 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -18678,6 +18678,14 @@ ix86_print_operand_address_as (FILE *file, rtx addr,
code = 'k';
}
+ /* Since the upper 32 bits of RSP are always zero for x32, we can
+ encode %esp as %rsp to avoid 0x67 prefix if there is no index or
+ base register. */
+ if (TARGET_X32 && Pmode == SImode
+ && ((!index && base && REGNO (base) == SP_REG)
+ || (!base && index && REGNO (index) == SP_REG)))
+ code = 'q';
+
if (ASSEMBLER_DIALECT == ASM_ATT)
{
if (disp)
diff --git a/gcc/testsuite/gcc.target/i386/pr82267.c b/gcc/testsuite/gcc.target/i386/pr82267.c
new file mode 100644
index 00000000000..5e4b271d41d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr82267.c
@@ -0,0 +1,14 @@
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-require-effective-target maybe_x32 } */
+/* { dg-options "-O2 -mx32 -maddress-mode=short" } */
+
+int
+stackuse (void)
+{
+ volatile int foo = 2;
+ return foo * 3;
+}
+
+/* Verify we that use %rsp to access stack. */
+/* { dg-final { scan-assembler-not "%esp" } } */
+/* { dg-final { scan-assembler "%rsp" } } */