From patchwork Wed Mar 12 17:01:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Mi X-Patchwork-Id: 329568 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id AB52E2C00B9 for ; Thu, 13 Mar 2014 04:01:36 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:cc:content-type; q=dns; s=default; b=OwENF1gK/2XFdRBEPE9KW8EaUtHNXChsRF8uqi8wqUp cmQ+h447J/37QjMk8DWHSd7ov4cuGSdMoSWdRV4C2yYpIvapOl6iV8FyoGScLXfS u0EkVfUNREdXZP6qjJW5jsI/00r5CL6TTSjj0d23QYll6LINLh/pvKfEtPaCF0DM = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:cc:content-type; s=default; bh=O1T4LnevbrEHWphOK9AhLPG8jzw=; b=RacVQVmlYSSR1el02 0HFdHVvfJr2Toy/fRUijBdI9+/jDKAjnJA5bTm4uCrPUtHI7DzvGJ3C50q/CJevB fB60tanYkjbu1M7SMIJY7UQSmDjg1dyhGXC0xhQfnpq9Szg8lkCbTWbSKdNWQv++ v2ZCaMWw5+7UMY+8oINXOUd5D0= Received: (qmail 1886 invoked by alias); 12 Mar 2014 17:01:28 -0000 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 Received: (qmail 1874 invoked by uid 89); 12 Mar 2014 17:01:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-oa0-f43.google.com Received: from mail-oa0-f43.google.com (HELO mail-oa0-f43.google.com) (209.85.219.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 12 Mar 2014 17:01:26 +0000 Received: by mail-oa0-f43.google.com with SMTP id g12so10478476oah.16 for ; Wed, 12 Mar 2014 10:01:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc :content-type; bh=oOw3Gq5gjDIe+0vxiLyjRgO1Q5t7oK3haBc9uzmL8Yg=; b=Yp1m+fqCLlHmhVP8QbmzLqsQ1EP9i/QNDgf4CM+2rNDZeSFNZghqga2yfU+D1fnfZ+ zb2UMPzjl+7rNqGRBawiHApUWKhIa9mb4UCK/uGa+ebfmg7/CRz7WZT3XnGyMzJG9Dw+ KXVToU5ZuDcpOhpV4DgBcvU3BmMN6e7oOYyH/uhIH1SbyaKAXIIEv24sqUkEZUwlG2bl qiVLxuJN1u1aYdokgqMehZSJZ81YN9I6MB1Tm8QRqR4BpIw1TOybVve4pmVhTHKdfZjw Utpkm668DowMkD8N420QM1rdUA78aOFER8HDBpgZeZtANf2ApA80oxRO6i4pnsZrNPEZ 3chw== X-Gm-Message-State: ALoCoQnCOjcBxO6E4+B3K4x36SglI3YEhg4wb2YMaI70JtLkjS5GLBVsfHMYd4DARi3+id1x5bgxbH9MBvFwWoV4el0qCO30VK5NlWEMtl7p8CQ7Z4KXaSkSiCMliaDJrq1PONweIaEvaAzHoo02BtIW9mXRQ83QGukbMxMVZDUywrnQ+M3H8O5hnO3RMg75foXeMQUrCnhP6tfa0KYq0+mGeolusefGCw== MIME-Version: 1.0 X-Received: by 10.182.241.8 with SMTP id we8mr1522224obc.62.1394643684973; Wed, 12 Mar 2014 10:01:24 -0700 (PDT) Received: by 10.76.180.234 with HTTP; Wed, 12 Mar 2014 10:01:24 -0700 (PDT) Date: Wed, 12 Mar 2014 10:01:24 -0700 Message-ID: Subject: [GOOGLE, PR58066] preferred_stack_boundary update for tls expanded call From: Wei Mi To: GCC Patches Cc: David Li , Paul Pluzhnikov This patch is to fix the problem described here: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58066 The original patch is here: http://gcc.gnu.org/ml/gcc-patches/2014-03/msg00369.html The attached patch addresses HJ's comment. bootstrap, regression test is ok. perf test in plain mode is ok. ok for google-4_8 branch? Thanks, Wei. gcc/ChangeLog: 2014-03-07 Wei Mi * config/i386/i386.c (ix86_compute_frame_layout): update preferred_stack_boundary when there is tls expanded call. * config/i386/i386.md: set ix86_tls_descriptor_calls_expanded_in_cfun. gcc/testsuite/ChangeLog: 2014-03-07 Wei Mi * g++.dg/pr58066.C: New test. Index: config/i386/i386.c =================================================================== --- config/i386/i386.c (revision 208464) +++ config/i386/i386.c (working copy) @@ -9211,6 +9211,19 @@ ix86_compute_frame_layout (struct ix86_f crtl->preferred_stack_boundary = 128; crtl->stack_alignment_needed = 128; } + /* For 64-bit target, preferred_stack_boundary is never updated for call + expanded from tls descriptor. Update it here. We don't update it in + expand stage because according to the comments before + ix86_current_function_calls_tls_descriptor, tls calls may be optimized + away. */ + else if (TARGET_64BIT + && ix86_current_function_calls_tls_descriptor + && crtl->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY) + { + crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY; + if (crtl->stack_alignment_needed < PREFERRED_STACK_BOUNDARY) + crtl->stack_alignment_needed = PREFERRED_STACK_BOUNDARY; + } gcc_assert (!size || stack_alignment_needed); gcc_assert (preferred_alignment >= STACK_BOUNDARY / BITS_PER_UNIT); Index: config/i386/i386.md =================================================================== --- config/i386/i386.md (revision 208464) +++ config/i386/i386.md (working copy) @@ -12776,7 +12776,11 @@ UNSPEC_TLS_GD)) (clobber (match_scratch:SI 4)) (clobber (match_scratch:SI 5)) - (clobber (reg:CC FLAGS_REG))])]) + (clobber (reg:CC FLAGS_REG))])] + "" +{ + ix86_tls_descriptor_calls_expanded_in_cfun = true; +}) (define_insn "*tls_global_dynamic_64_" [(set (match_operand:P 0 "register_operand" "=a") @@ -12809,7 +12813,10 @@ (const_int 0))) (unspec:P [(match_operand 1 "tls_symbolic_operand")] UNSPEC_TLS_GD)])] - "TARGET_64BIT") + "TARGET_64BIT" +{ + ix86_tls_descriptor_calls_expanded_in_cfun = true; +}) (define_insn "*tls_local_dynamic_base_32_gnu" [(set (match_operand:SI 0 "register_operand" "=a") @@ -12844,7 +12851,11 @@ UNSPEC_TLS_LD_BASE)) (clobber (match_scratch:SI 3)) (clobber (match_scratch:SI 4)) - (clobber (reg:CC FLAGS_REG))])]) + (clobber (reg:CC FLAGS_REG))])] + "" +{ + ix86_tls_descriptor_calls_expanded_in_cfun = true; +}) (define_insn "*tls_local_dynamic_base_64_" [(set (match_operand:P 0 "register_operand" "=a") @@ -12870,7 +12881,10 @@ (mem:QI (match_operand 1 "constant_call_address_operand")) (const_int 0))) (unspec:P [(const_int 0)] UNSPEC_TLS_LD_BASE)])] - "TARGET_64BIT") + "TARGET_64BIT" +{ + ix86_tls_descriptor_calls_expanded_in_cfun = true; +}) ;; Local dynamic of a single variable is a lose. Show combine how ;; to convert that back to global dynamic. Index: testsuite/g++.dg/pr58066.C =================================================================== --- testsuite/g++.dg/pr58066.C (revision 0) +++ testsuite/g++.dg/pr58066.C (revision 0) @@ -0,0 +1,12 @@ +/* { dg-do compile { target {{ i?86-*-* x86_64-*-* } && { ! ia32 } } } } */ +/* { dg-options "-fPIC -O2" } */ + +/* Check whether the stack frame starting address of tls expanded call + in __cxa_get_globals() is 16bytes aligned. */ +static __thread char ccc; +extern "C" void* __cxa_get_globals() throw() +{ + return &ccc; +} + +/* { dg-final { scan-assembler ".cfi_def_cfa_offset 16" } } */