From patchwork Sat Dec 15 19:22:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1013987 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-492577-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="QIIE/TLO"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="u6GNEg2n"; 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 43HHPR17C1z9s6w for ; Sun, 16 Dec 2018 06:22:50 +1100 (AEDT) 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=aVCXPkCbgQZ5rstUTEKVzq7TnUQ/aM2qXOMOGD5lJ5DPLBWH0R Hgw7U5oL/uHkmAf+aFPV0meEpeiW5iRNg3jaVLqKYPKQTy/1QCmMDNBpnJCS1c4c /u6J5deJ43/AEoKMW73DWv/XUQ8895QURDUS/3k/2wS9/JMHOB4mnWuKk= 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=IReB6k5BjVmgJhEKK/cHvkUkPgI=; b=QIIE/TLOpW6ihzu6DdvW Wtj6ltoAk8Bz3V9ss6LOpsegSjJZvfxR1YfMmZwZbtpmlIUzQErkzBzzY0sY6636 ULe3fCDGFaUUwU61Rwkzk8+ZE2KbKDxdT6khp7+DRZohRGH0CvD0oNfEPngxTSYZ 0fG8XrDrHG3sCkZ9TbFbj5E= Received: (qmail 61416 invoked by alias); 15 Dec 2018 19:22:43 -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 61405 invoked by uid 89); 15 Dec 2018 19:22:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=i386.h, i386h, UD:i386.h, Hx-spam-relays-external:209.85.215.196 X-HELO: mail-pg1-f196.google.com Received: from mail-pg1-f196.google.com (HELO mail-pg1-f196.google.com) (209.85.215.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 15 Dec 2018 19:22:41 +0000 Received: by mail-pg1-f196.google.com with SMTP id y4so4198256pgc.12 for ; Sat, 15 Dec 2018 11:22:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=TbHqdswuHocb3oUDWoLPADh5ArVtACV7P6VQU1Nk+X0=; b=u6GNEg2nM5G+N1LiVPouF30Tg1owt6rnlQqQiWrEG7HYHrqxXkHjvP1BN61vNQfZOL Oq9tAMUXIc+bp8poFWoJBPZ8kbm3sQqjNu2yR1Xk0VryS3RJ2mrAIABlqyPl4r/BPkmo 2PAbLAV6/Np7heNj7xUEuVVmxCvEYhY3U/xtsIJtQUM8Ei+4QDslj2b+fSfYL7LTM5md 93yzpOhMkL7SNkEjozFCb2pbFqeo/nR8PdSSE+Oa+7MohXp2I9UDrDieisjWVIEfaF9C 9oLKsXASAyUw+Z5aMrHlSeSghHWXmdK0FeR6t1ZywYTo84lnXmXkwmmB7ypX3Uc3/XhZ PU/A== Received: from gnu-cfl-2.localdomain (c-73-93-86-59.hsd1.ca.comcast.net. [73.93.86.59]) by smtp.gmail.com with ESMTPSA id 34sm10654867pgp.90.2018.12.15.11.22.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 15 Dec 2018 11:22:39 -0800 (PST) Received: by gnu-cfl-2.localdomain (Postfix, from userid 1000) id 39C83C015D; Sat, 15 Dec 2018 11:22:38 -0800 (PST) Date: Sat, 15 Dec 2018 11:22:38 -0800 From: "H.J. Lu" To: Uros Bizjak Cc: "gcc-patches@gcc.gnu.org" Subject: [PATCH] x86: Set frame size to 0 if stack frame isn't required Message-ID: <20181215192238.GB11904@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-IsSubscribed: yes get_frame_size () returns used stack slots during compilation, which may be optimized out later. Since ix86_find_max_used_stack_alignment checks if stack frame is required, it can set a bit in machine_function to let ix86_compute_frame_layout know that stack frame isn't required. Tested on i686 and x86-64 with --with-arch=native --with-cpu=native on AVX512 machine. Tested on i686 and x86-64 without --with-arch=native --with-cpu=native on x86-64 machine. OK for trunk? Thanks. H.J. --- gcc/ PR target/88496 * config/i386/i386.c (ix86_compute_frame_layout): Set frame size to 0 if the function doesn't need a stack frame. (ix86_find_max_used_stack_alignment): Set no_stack_frame to 1 if stack frame isn't required. * config/i386/i386.h (machine_function): Add no_stack_frame. gcc/testsuite/ PR target/88496 * gcc.target/i386/pr88496.c: New test. --- gcc/config/i386/i386.c | 10 +++++++++- gcc/config/i386/i386.h | 3 +++ gcc/testsuite/gcc.target/i386/pr88496.c | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr88496.c diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index b6dea0c061d..3ef9c967bd6 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -11164,9 +11164,14 @@ ix86_compute_frame_layout (void) unsigned HOST_WIDE_INT stack_alignment_needed; HOST_WIDE_INT offset; unsigned HOST_WIDE_INT preferred_alignment; - HOST_WIDE_INT size = get_frame_size (); + HOST_WIDE_INT size; HOST_WIDE_INT to_allocate; + if (cfun->machine->no_stack_frame) + size = HOST_WIDE_INT_C (0); + else + size = get_frame_size (); + /* m->call_ms2sysv is initially enabled in ix86_expand_call for all 64-bit * ms_abi functions that call a sysv function. We now need to prune away * cases where it should be disabled. */ @@ -12830,6 +12835,9 @@ ix86_find_max_used_stack_alignment (unsigned int &stack_alignment, } } + if (!require_stack_frame) + cfun->machine->no_stack_frame = 1; + return require_stack_frame; } diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h index 64fc5d4058a..4ee86973977 100644 --- a/gcc/config/i386/i386.h +++ b/gcc/config/i386/i386.h @@ -2754,6 +2754,9 @@ struct GTY(()) machine_function { /* If true, ENDBR is queued at function entrance. */ BOOL_BITFIELD endbr_queued_at_entrance : 1; + /* Nonzero if the function doesn't need a stack frame. */ + BOOL_BITFIELD no_stack_frame : 1; + /* The largest alignment, in bytes, of stack slot actually used. */ unsigned int max_used_stack_alignment; diff --git a/gcc/testsuite/gcc.target/i386/pr88496.c b/gcc/testsuite/gcc.target/i386/pr88496.c new file mode 100644 index 00000000000..c07ab594414 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr88496.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mavx512f" } */ + +struct B +{ + char a[12]; + int b; +}; + +struct B +f2 (void) +{ + struct B x = {}; + return x; +} + +/* { dg-final { scan-assembler-not "(sub|add)(l|q)\[\\t \]*\\$\[0-9\]*,\[\\t \]*%\[re\]?sp" } } */