From patchwork Sat Nov 12 17:47:17 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 125367 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id A15251007D8 for ; Sun, 13 Nov 2011 04:47:34 +1100 (EST) Received: (qmail 13253 invoked by alias); 12 Nov 2011 17:47:32 -0000 Received: (qmail 13243 invoked by uid 22791); 12 Nov 2011 17:47:31 -0000 X-SWARE-Spam-Status: No, hits=-5.6 required=5.0 tests=AWL, BAYES_00, NO_DNS_FOR_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, TW_DD, TW_OV X-Spam-Check-By: sourceware.org Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 12 Nov 2011 17:47:18 +0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 12 Nov 2011 09:47:17 -0800 X-ExtLoop1: 1 Received: from gnu-6.sc.intel.com ([10.3.194.135]) by fmsmga002.fm.intel.com with ESMTP; 12 Nov 2011 09:47:17 -0800 Received: by gnu-6.sc.intel.com (Postfix, from userid 500) id 7B0A0C272D; Sat, 12 Nov 2011 09:47:17 -0800 (PST) Date: Sat, 12 Nov 2011 09:47:17 -0800 From: "H.J. Lu" To: gcc-patches@gcc.gnu.org, Uros Bizjak , Richard Henderson Subject: PATCH [2/n] addr32: Output REX prefix for UNSPEC_GOTNTPOFF Message-ID: <20111112174717.GA10272@intel.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org X86-64 linker optimizes TLS_MODEL_INITIAL_EXEC to TLS_MODEL_LOCAL_EXEC by checking movq foo@gottpoff(%rip), %reg and addq foo@gottpoff(%rip), %reg It uses the REX prefix to avoid the last byte of the previous instruction. With 32bit Pmode, we may not have the REX prefix and the last byte of the previous instruction may be an offset, which may look like a REX prefix. IE->LE optimization will generate corrupted binary. This patch makes sure we always output an REX pfrefix for UNSPEC_GOTNTPOFF. OK for trunk? Thanks. H.J. --- 2011-11-12 H.J. Lu * config/i386/i386-protos.h (ix86_output_rex_prefix_p): New. * config/i386/i386.c (ix86_output_rex_prefix_p): Likewise. * config/i386/i386.md (*movsi_internal): Output REX prefix if needed. (*add_1): Likewise. diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h index 5486e61..14af5e6 100644 --- a/gcc/config/i386/i386-protos.h +++ b/gcc/config/i386/i386-protos.h @@ -274,6 +274,8 @@ extern void x86_output_aligned_bss (FILE *, tree, const char *, extern void x86_elf_aligned_common (FILE *, const char *, unsigned HOST_WIDE_INT, int); +extern bool ix86_output_rex_prefix_p (rtx, rtx); + #ifdef RTX_CODE extern void ix86_fp_comparison_codes (enum rtx_code code, enum rtx_code *, enum rtx_code *, enum rtx_code *); diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index f73bb94..81ff746 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -14510,6 +14510,29 @@ i386_asm_output_addr_const_extra (FILE *file, rtx x) return true; } + +/* Since x64-64 linker IE->LE transition requires a REX prefix, we + output a REX prefix if there isn't one. */ + +bool +ix86_output_rex_prefix_p (rtx dest, rtx op) +{ + if (!TARGET_X32 + || GET_MODE (dest) != SImode + || REX_INT_REG_P (dest) + || !MEM_P (op)) + return false; + + op = XEXP (op, 0); + if (GET_CODE (op) != CONST) + return false; + + op = XEXP (op, 0); + if (GET_CODE (op) != UNSPEC) + return false; + + return XINT (op, 1) == UNSPEC_GOTNTPOFF; +} /* Split one or more double-mode RTL references into pairs of half-mode references. The RTL can be REG, offsettable MEM, integer constant, or diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 9d2d084..5660ea2 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -2287,7 +2287,11 @@ default: gcc_assert (!flag_pic || LEGITIMATE_PIC_OPERAND_P (operands[1])); - return "mov{l}\t{%1, %0|%0, %1}"; + /* Output REX prefix if needed. */ + if (ix86_output_rex_prefix_p (operands[0], operands[1])) + return "rex mov{l}\t{%1, %0|%0, %1}"; + else + return "mov{l}\t{%1, %0|%0, %1}"; } } [(set (attr "type") @@ -5616,7 +5620,11 @@ if (x86_maybe_negate_const_int (&operands[2], mode)) return "sub{}\t{%2, %0|%0, %2}"; - return "add{}\t{%2, %0|%0, %2}"; + /* Output REX prefix if needed. */ + if (ix86_output_rex_prefix_p (operands[0], operands[2])) + return "rex add{}\t{%2, %0|%0, %2}"; + else + return "add{}\t{%2, %0|%0, %2}"; } } [(set (attr "type")