From patchwork Fri May 6 02:17:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 94337 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 291C5B700D for ; Fri, 6 May 2011 12:17:33 +1000 (EST) Received: (qmail 15875 invoked by alias); 6 May 2011 02:17:26 -0000 Received: (qmail 15782 invoked by uid 22791); 6 May 2011 02:17:25 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RFC_ABUSE_POST, T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-pz0-f47.google.com (HELO mail-pz0-f47.google.com) (209.85.210.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 06 May 2011 02:17:11 +0000 Received: by pzk36 with SMTP id 36so1436232pzk.20 for ; Thu, 05 May 2011 19:17:11 -0700 (PDT) Received: by 10.68.65.116 with SMTP id w20mr669267pbs.383.1304648230954; Thu, 05 May 2011 19:17:10 -0700 (PDT) Received: from bubble.grove.modra.org ([115.187.252.19]) by mx.google.com with ESMTPS id r7sm1813210pbo.52.2011.05.05.19.17.09 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 05 May 2011 19:17:10 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 186C5170C2B9; Fri, 6 May 2011 11:47:05 +0930 (CST) Date: Fri, 6 May 2011 11:47:05 +0930 From: Alan Modra To: gcc-patches@gcc.gnu.org Cc: David Edelsohn Subject: Fix PR48900, powerpc duplicate __tls_get_addr calls Message-ID: <20110506021704.GL7018@bubble.grove.modra.org> Mail-Followup-To: gcc-patches@gcc.gnu.org, David Edelsohn MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) 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 My fix for PR44266 using the libcall machinery to ensure we had a proper stack frame allocated for __tls_get_addr calls sloppily used r3 as the arg to the dummy libcall. This made the call seem to depend on whatever was in r3 previously, at least until we get to the first split pass and the real arg is exposed. So DCE couldn't merge calls. Even for a simple testcase like extern __thread int i; void foo (void) { i++; } we get two __tls_get_addr calls if using global-dynamic tls model. Easliy fixed by giving the dummy libcall an arg of zero. An alternative giving slightly better -O0 code would be to say that the libcall doesn't have any args. I chose to leave the libcall with one arg since this is closest to the real __tls_get_addr call, and the whole point of faking up a libcall here is to have the generic code do whatever is necessary when making function calls. It's not totally impossible to imagine some future ABI change that treats zero arg calls differently from other calls. Bootstrapped and regression tested powerpc64-linux. OK to apply mainline, 4.6 and 4.5? PR target/48900 * config/rs6000/rs6000.c (rs6000_legitimize_tls_address): Use const0_rtx as the arg to the dummy __tls_get_addr libcall. Index: gcc/config/rs6000/rs6000.c =================================================================== --- gcc/config/rs6000/rs6000.c (revision 173464) +++ gcc/config/rs6000/rs6000.c (working copy) @@ -6412,10 +6412,11 @@ rs6000_legitimize_tls_address (rtx addr, if (model == TLS_MODEL_GLOBAL_DYNAMIC) { - r3 = gen_rtx_REG (Pmode, 3); tga = rs6000_tls_get_addr (); - emit_library_call_value (tga, dest, LCT_CONST, Pmode, 1, r3, Pmode); + emit_library_call_value (tga, dest, LCT_CONST, Pmode, + 1, const0_rtx, Pmode); + r3 = gen_rtx_REG (Pmode, 3); if (DEFAULT_ABI == ABI_AIX && TARGET_64BIT) insn = gen_tls_gd_aix64 (r3, got, addr, tga, const0_rtx); else if (DEFAULT_ABI == ABI_AIX && !TARGET_64BIT) @@ -6432,11 +6433,12 @@ rs6000_legitimize_tls_address (rtx addr, } else if (model == TLS_MODEL_LOCAL_DYNAMIC) { - r3 = gen_rtx_REG (Pmode, 3); tga = rs6000_tls_get_addr (); tmp1 = gen_reg_rtx (Pmode); - emit_library_call_value (tga, tmp1, LCT_CONST, Pmode, 1, r3, Pmode); + emit_library_call_value (tga, tmp1, LCT_CONST, Pmode, + 1, const0_rtx, Pmode); + r3 = gen_rtx_REG (Pmode, 3); if (DEFAULT_ABI == ABI_AIX && TARGET_64BIT) insn = gen_tls_ld_aix64 (r3, got, tga, const0_rtx); else if (DEFAULT_ABI == ABI_AIX && !TARGET_64BIT)