From patchwork Fri Oct 8 19:31:41 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 67273 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 8EA8A100805 for ; Sat, 9 Oct 2010 06:29:50 +1100 (EST) Received: (qmail 29566 invoked by alias); 8 Oct 2010 19:29:48 -0000 Received: (qmail 29556 invoked by uid 22791); 8 Oct 2010 19:29:47 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 08 Oct 2010 19:29:41 +0000 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o98JTeTe030307 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 8 Oct 2010 15:29:40 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o98JTcMo009172 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 8 Oct 2010 15:29:39 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id o98JVgcT026103; Fri, 8 Oct 2010 21:31:42 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o98JVgUd026101; Fri, 8 Oct 2010 21:31:42 +0200 Date: Fri, 8 Oct 2010 21:31:41 +0200 From: Jakub Jelinek To: Uros Bizjak , Richard Henderson Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Delegitimize TLS local-exec accesses on i?86/x86_64 (PR target/45870) Message-ID: <20101008193141.GP4127@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-12-10) X-IsSubscribed: yes 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 Hi! This patch delegitimizes TLS local-exec mode accesses, if both UNSPEC_TP and UNSPEC_NTPOFF is present in the address. On the attached testcase it gets rid of the --enable-checking=yes notes about non-delegitimized UNSPECs in debug info output. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2010-10-08 Jakub Jelinek PR target/45870 * config/i386/i386.c (ix86_delegitimize_tls_address): New function. (ix86_delegitimize_address): Use it. * gcc.dg/tls/pr45870.c: New test. Jakub --- gcc/config/i386/i386.c.jj 2010-10-07 19:45:19.000000000 +0200 +++ gcc/config/i386/i386.c 2010-10-07 22:26:01.000000000 +0200 @@ -12305,6 +12305,49 @@ ix86_pic_register_p (rtx x) return REG_P (x) && REGNO (x) == PIC_OFFSET_TABLE_REGNUM; } +/* Helper function for ix86_delegitimize_address. + Attempt to delegitimize TLS local-exec accesses. */ + +static rtx +ix86_delegitimize_tls_address (rtx orig_x) +{ + rtx x = orig_x, unspec; + struct ix86_address addr; + + if (!TARGET_TLS_DIRECT_SEG_REFS) + return orig_x; + if (MEM_P (x)) + x = XEXP (x, 0); + if (GET_CODE (x) != PLUS || GET_MODE (x) != Pmode) + return orig_x; + if (ix86_decompose_address (x, &addr) == 0 + || addr.seg != (TARGET_64BIT ? SEG_FS : SEG_GS) + || addr.disp == NULL_RTX + || GET_CODE (addr.disp) != CONST) + return orig_x; + unspec = XEXP (addr.disp, 0); + if (GET_CODE (unspec) == PLUS && CONST_INT_P (XEXP (unspec, 1))) + unspec = XEXP (unspec, 0); + if (GET_CODE (unspec) != UNSPEC || XINT (unspec, 1) != UNSPEC_NTPOFF) + return orig_x; + x = XVECEXP (unspec, 0, 0); + gcc_assert (GET_CODE (x) == SYMBOL_REF); + if (unspec != XEXP (addr.disp, 0)) + x = gen_rtx_PLUS (Pmode, x, XEXP (XEXP (addr.disp, 0), 1)); + if (addr.index) + { + rtx idx = addr.index; + if (addr.scale != 1) + idx = gen_rtx_MULT (Pmode, idx, GEN_INT (addr.scale)); + x = gen_rtx_PLUS (Pmode, idx, x); + } + if (addr.base) + x = gen_rtx_PLUS (Pmode, addr.base, x); + if (MEM_P (orig_x)) + x = replace_equiv_address_nv (orig_x, x); + return x; +} + /* In the name of slightly smaller debug output, and to cater to general assembler lossage, recognize PIC+GOTOFF and turn it back into a direct symbol reference. @@ -12340,7 +12383,7 @@ ix86_delegitimize_address (rtx x) || GET_CODE (XEXP (x, 0)) != UNSPEC || XINT (XEXP (x, 0), 1) != UNSPEC_GOTPCREL || !MEM_P (orig_x)) - return orig_x; + return ix86_delegitimize_tls_address (orig_x); x = XVECEXP (XEXP (x, 0), 0, 0); if (GET_MODE (orig_x) != Pmode) return simplify_gen_subreg (GET_MODE (orig_x), x, Pmode, 0); @@ -12349,7 +12392,7 @@ ix86_delegitimize_address (rtx x) if (GET_CODE (x) != PLUS || GET_CODE (XEXP (x, 1)) != CONST) - return orig_x; + return ix86_delegitimize_tls_address (orig_x); if (ix86_pic_register_p (XEXP (x, 0))) /* %ebx + GOT/GOTOFF */ @@ -12389,7 +12432,7 @@ ix86_delegitimize_address (rtx x) result = XVECEXP (x, 0, 0); if (! result) - return orig_x; + return ix86_delegitimize_tls_address (orig_x); if (const_addend) result = gen_rtx_CONST (Pmode, gen_rtx_PLUS (Pmode, result, const_addend)); --- gcc/testsuite/gcc.dg/tls/pr45870.c.jj 2010-10-07 22:19:18.000000000 +0200 +++ gcc/testsuite/gcc.dg/tls/pr45870.c 2010-10-07 22:19:07.000000000 +0200 @@ -0,0 +1,21 @@ +/* PR target/45870 */ +/* { dg-do compile } */ +/* { dg-options "-g -O" } */ +/* { dg-require-effective-target tls } */ + +__thread int v[30]; +int bar (void); + +int +foo (int x, int y, int z) +{ + int a, b = z, c; + while (b > 0) + { + c = (bar () % 3); + a = v[x]; + if (x < y) + for (;;); + b += a; + } +}