From patchwork Fri Mar 2 20:36:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 144338 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 3D11DB6ED0 for ; Sat, 3 Mar 2012 07:36:37 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1331325398; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Date:From:To:Subject:Message-ID:Reply-To:MIME-Version: Content-Type:Content-Disposition:User-Agent:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=woFyttFeKI6tZnJS8qfga9oamLw=; b=cq/02GczgQxvtf25b9YJad/etsP6bHsfFs9WzdrQj7Rk3MJkAnfMKN/MM7KBna 26FtupPFUDeJyyLlssxyi73kOH6wGuhLxV73T9EY7AMB511AO3zv6FJPgE3fZNV1 MOsBrTUvCju7+WAid5E8n+dySWKUmq32z50Hd//Utx4qE= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-ExtLoop1:Received:Received:Date:From:To:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=M1ZnbBVLIfEqcYh7AdCFPow7TGiuziEpb1VuhJgWqrdJAHtkB8P58XojtGSJcN B5zeDZ8/wUzsyxur6bnsm/VwZx+DbVrvtqF7kk38/taXkf+zbe7mCF5pTjTFPwSB 8/Enqs/1fYN/w9l4gZJ2kw2VaDBFtgmvY71xfJkf3Snas=; Received: (qmail 13109 invoked by alias); 2 Mar 2012 20:36:30 -0000 Received: (qmail 12878 invoked by uid 22791); 2 Mar 2012 20:36:28 -0000 X-SWARE-Spam-Status: No, hits=-4.0 required=5.0 tests=AWL, BAYES_00, NO_DNS_FOR_FROM, RCVD_IN_DNSWL_HI, TW_DD, TW_OV, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 02 Mar 2012 20:36:15 +0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 02 Mar 2012 12:36:14 -0800 X-ExtLoop1: 1 Received: from gnu-6.sc.intel.com ([10.3.194.135]) by orsmga002.jf.intel.com with ESMTP; 02 Mar 2012 12:36:14 -0800 Received: by gnu-6.sc.intel.com (Postfix, from userid 500) id 7087FC186C; Fri, 2 Mar 2012 12:36:14 -0800 (PST) Date: Fri, 2 Mar 2012 12:36:14 -0800 From: "H.J. Lu" To: gcc-patches@gcc.gnu.org, Uros Bizjak , Richard Henderson Subject: [PATCH 02/10] addr32: Output REX prefix for UNSPEC_GOTNTPOFF Message-ID: <20120302203614.GA2179@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. 2012-03-02 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 630112f..a9b9d3f 100644 --- a/gcc/config/i386/i386-protos.h +++ b/gcc/config/i386/i386-protos.h @@ -277,6 +277,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 ac9c714..2cbfb64 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -14670,6 +14670,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 8fc7918..35b2673 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -2211,7 +2211,13 @@ if (ix86_use_lea_for_mov (insn, operands)) return "lea{l}\t{%a1, %0|%0, %a1}"; else - 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") @@ -5540,7 +5546,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")