From patchwork Mon Sep 11 01:57:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 812210 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-461791-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="SgrNsJj7"; dkim-atps=neutral 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 3xr9zr1NR3z9s82 for ; Mon, 11 Sep 2017 11:57:41 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=W7GHztIXX88F6n3XyJpRBQBr6XiWjyvuCfiQdxmm22/t0LsBeW g+YN8E+LtDKVng9pKx12ncBT63DB84kpicZEW540E/VxmvCYEoNnlTyRBeTqrXFm 0wl+6qBsy+h+OnPP250DV1Q3jR/FA6vIw5kuWTHV64pU7b1Fk7KyKPq1M= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=9oJ7qy/t30qao0Q0nClRyVHSJDc=; b=SgrNsJj7HRNsdB02dCo1 Wa7x6kkwlC1Go278d5UnhDCRG9ZJmPxCDtpk5njl8TJDyOxm6IvGNDH+0iUaqM6r gkAMpYiV7Yn86CyPJn0QV69UUx2uSwctaQzXlz4wh9Ea2hPp70asZ8dXxerhI772 IlxaYmSw0b36xQ0IBwDe+eg= Received: (qmail 100438 invoked by alias); 11 Sep 2017 01:57:32 -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 100320 invoked by uid 89); 11 Sep 2017 01:57:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-spam-relays-external:74.125.83.68, H*RU:74.125.83.68 X-HELO: mail-pg0-f68.google.com Received: from mail-pg0-f68.google.com (HELO mail-pg0-f68.google.com) (74.125.83.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 11 Sep 2017 01:57:30 +0000 Received: by mail-pg0-f68.google.com with SMTP id j16so894783pga.2 for ; Sun, 10 Sep 2017 18:57:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=VHZ2zuf9VsJl3PTOfjsb8Rb2ZuHvfUnjYKncuCbnVzA=; b=EKZQ2jT1UJ6+CpIP7+aYq15IHL4x3Wv+/wxSLGTmTWMvovBo2oJYwEQ8HSzUoU3OKa xHiInE3U9U7qvL23fqSqpjIjo6yeCrfseyuVug5bAGsgSg2pMTZEcnj6G07TVl7wnkeP EGH8Fk4/lU3K/n9bkpHwOQT2NIp9+dSokAkZ7pv66c+PNxpwOTE3PiwoK0jrCSfzNDTY gwf687YHcgR2Oe+9RavryBHDEkouR/U+v3no73wH47fAxJVb0X+ILEjWwq3oUOybL3Fo 2hUDTmUw1s7RcFii4ZElL6atBxNKF/ngaG0YpGspyFn3cpxyJsTRS2vb6VahgWgAslPf /0kA== X-Gm-Message-State: AHPjjUgwz1J+FhpWX+FBys8qxXn0U0u+9VDXlifFvfatTzILN6AyjJDv GPfhciJQbluguvKg X-Google-Smtp-Source: ADKCNb5DeksiYc+LNM5L/EYaRg+SXtb6egumTUrrOhoovktX9Y2YFP/S9n3BFOWGDZa5W+lNGioK5g== X-Received: by 10.99.136.73 with SMTP id l70mr10360996pgd.185.1505095048151; Sun, 10 Sep 2017 18:57:28 -0700 (PDT) Received: from gnu-tools-1.localdomain (c-73-93-86-59.hsd1.ca.comcast.net. [73.93.86.59]) by smtp.gmail.com with ESMTPSA id s81sm13720666pfg.162.2017.09.10.18.57.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 10 Sep 2017 18:57:27 -0700 (PDT) Received: by gnu-tools-1.localdomain (Postfix, from userid 1000) id A1F631C0BF1; Sun, 10 Sep 2017 18:57:26 -0700 (PDT) Date: Sun, 10 Sep 2017 18:57:26 -0700 From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: Uros Bizjak Subject: [PATCH] PR target/82166: Update preferred stack boundary for leaf functions Message-ID: <20170911015726.GA24758@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.8.3 (2017-05-23) X-IsSubscribed: yes preferred_stack_boundary may not be the minimum stack alignment. For leaf functions without TLS access, max_used_stack_slot_alignment may be smaller. We should update preferred_stack_boundary for leaf functions. Tested on i686 and x86-64. OK for trunk? H.J. --- gcc/ PR target/82166 * config/i386/i386.c (ix86_finalize_stack_frame_flags): Properly compute the minimum stack alignment. Also update preferred stack boundary when main () is a leaf function. gcc/testsuite/ PR target/82166 * gcc.target/i386/pr82166.c: New test. --- gcc/config/i386/i386.c | 17 ++++++++++++----- gcc/testsuite/gcc.target/i386/pr82166.c | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr82166.c diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 4e93cc1043b..03338e422be 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -14257,11 +14257,12 @@ ix86_finalize_stack_frame_flags (void) unsigned int incoming_stack_boundary = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary); + unsigned int stack_alignment + = (crtl->is_leaf && !ix86_current_function_calls_tls_descriptor + ? crtl->max_used_stack_slot_alignment + : crtl->stack_alignment_needed); unsigned int stack_realign - = (incoming_stack_boundary - < (crtl->is_leaf && !ix86_current_function_calls_tls_descriptor - ? crtl->max_used_stack_slot_alignment - : crtl->stack_alignment_needed)); + = (incoming_stack_boundary < stack_alignment); bool recompute_frame_layout_p = false; if (crtl->stack_realign_finalized) @@ -14306,7 +14307,9 @@ ix86_finalize_stack_frame_flags (void) HARD_FRAME_POINTER_REGNUM); /* The preferred stack alignment is the minimum stack alignment. */ - unsigned int stack_alignment = crtl->preferred_stack_boundary; + if (stack_alignment > crtl->preferred_stack_boundary) + stack_alignment = crtl->preferred_stack_boundary; + bool require_stack_frame = false; FOR_EACH_BB_FN (bb, cfun) @@ -14349,6 +14352,10 @@ ix86_finalize_stack_frame_flags (void) = incoming_stack_boundary; crtl->stack_alignment_needed = incoming_stack_boundary; + /* Also update preferred_stack_boundary for leaf + functions. */ + crtl->preferred_stack_boundary + = incoming_stack_boundary; } } else diff --git a/gcc/testsuite/gcc.target/i386/pr82166.c b/gcc/testsuite/gcc.target/i386/pr82166.c new file mode 100644 index 00000000000..8bc63e15231 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr82166.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-Os" } */ + +void foo (void); +int a, b, c; +int +main (void) +{ + int j; + for (; c;) + a = b; + for (; j;) + foo (); +}