From patchwork Wed Feb 5 12:37:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 316944 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 DA7B62C0079 for ; Wed, 5 Feb 2014 23:37:35 +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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=FNrvwFILbf7/GZ7OnfnEjkiz1beMK WN0+iPvrPqIe757bCfZV+BVypdH+VA1FF21FgCiiEUDVeDGZ5jxa4OwFFhKGfNBQ Q1W9PlFXWsr9MNoPyRI122JEqtG6DuNw3Z/mhz5oPYxfZXRCbQ0W/mFKnN2C9R9g WFP9wIk6H0tdRM= 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:reply-to:mime-version :content-type; s=default; bh=/hOHW7cq9k0WjA4UeFx+svD3WTc=; b=NLI mE4FsSl18q90Hvwp3nPiZlXUlnR7TlBirQ2W6MbJiDPOR/WZ3e0Crv2wt02fwjCL IrgpEtYENcyOR0ITcC+xr88hnv7qLMs8Ua/iWHIFEWL+TskmJX27dpKk/mJ4fRHo jsKSYZ24V/aKxdszm3WlLqXv9IiUOvfUP4e4eW/c= Received: (qmail 20258 invoked by alias); 5 Feb 2014 12:37:29 -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 20248 invoked by uid 89); 5 Feb 2014 12:37:28 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-3.9 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Feb 2014 12:37:28 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s15CbROn010937 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 5 Feb 2014 07:37:27 -0500 Received: from tucnak.zalov.cz (vpn1-7-135.ams2.redhat.com [10.36.7.135]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s15CbOwu030917 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 5 Feb 2014 07:37:25 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.7/8.14.7) with ESMTP id s15CbNGI002531; Wed, 5 Feb 2014 13:37:23 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.7/8.14.7/Submit) id s15CbMSB002530; Wed, 5 Feb 2014 13:37:22 +0100 Date: Wed, 5 Feb 2014 13:37:22 +0100 From: Jakub Jelinek To: Richard Biener , Jan Hubicka , Uros Bizjak , Richard Henderson Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ix86_function_regparm with optimize attribute (PR target/60062) Message-ID: <20140205123722.GB12671@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: attachment User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi! Using !!optimize to determine if we should switch local ABI to regparm convention isn't compatible with optimize attribute, as !!optimize is whether the current function is being optimized, but for the ABI decisions we actually need the caller and callee to agree on the calling convention. Fixed by looking at callee's optimize settings all the time. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2014-02-05 Jakub Jelinek PR target/60062 * config/i386/i386.c (ix86_function_regparm): Use optimize from the callee instead of current function's optimize to determine if local regparm convention should be used. * gcc.c-torture/execute/pr60062.c: New test. * gcc.c-torture/execute/pr60072.c: New test. Jakub --- gcc/config/i386/i386.c.jj 2014-02-04 01:36:00.000000000 +0100 +++ gcc/config/i386/i386.c 2014-02-05 09:09:29.603827877 +0100 @@ -5608,11 +5608,22 @@ ix86_function_regparm (const_tree type, /* Use register calling convention for local functions when possible. */ if (decl && TREE_CODE (decl) == FUNCTION_DECL - && optimize && !(profile_flag && !flag_fentry)) { /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified. */ struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE (decl)); + + /* Caller and callee must agree on the calling convention, so + checking here just optimize means that with + __attribute__((optimize (...))) caller could use regparm convention + and callee not, or vice versa. Instead look at whether the callee + is optimized or not. */ + tree opts = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl); + if (opts == NULL_TREE) + opts = optimization_default_node; + if (!TREE_OPTIMIZATION (opts)->x_optimize) + i = NULL; + if (i && i->local && i->can_change_signature) { int local_regparm, globals = 0, regno; --- gcc/testsuite/gcc.c-torture/execute/pr60062.c.jj 2014-02-05 09:02:13.703085235 +0100 +++ gcc/testsuite/gcc.c-torture/execute/pr60062.c 2014-02-05 09:01:54.000000000 +0100 @@ -0,0 +1,25 @@ +/* PR target/60062 */ + +int a; + +static void +foo (const char *p1, int p2) +{ + if (__builtin_strcmp (p1, "hello") != 0) + __builtin_abort (); +} + +static void +bar (const char *p1) +{ + if (__builtin_strcmp (p1, "hello") != 0) + __builtin_abort (); +} + +__attribute__((optimize (0))) int +main () +{ + foo ("hello", a); + bar ("hello"); + return 0; +} --- gcc/testsuite/gcc.c-torture/execute/pr60072.c.jj 2013-08-25 18:20:55.717911035 +0200 +++ gcc/testsuite/gcc.c-torture/execute/pr60072.c 2014-02-05 11:33:07.501748426 +0100 @@ -0,0 +1,16 @@ +/* PR target/60072 */ + +int c = 1; + +__attribute__ ((optimize (1))) +static int *foo (int *p) +{ + return p; +} + +int +main () +{ + *foo (&c) = 2; + return c - 2; +}