From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 121065 invoked by alias); 1 May 2015 18:51:34 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 121056 invoked by uid 89); 1 May 2015 18:51:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 01 May 2015 18:51:31 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 772A091774; Fri, 1 May 2015 18:51:30 +0000 (UTC) Received: from localhost.localdomain (ovpn-113-143.phx2.redhat.com [10.3.113.143]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t41IpT8Z001454; Fri, 1 May 2015 14:51:29 -0400 Message-ID: <5543CB30.5060403@redhat.com> Date: Fri, 01 May 2015 18:51:00 -0000 From: Jeff Law User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Kyrill Tkachov , GCC Patches CC: Honggyu Kim Subject: Re: [PATCH][expr.c] PR 65358 Avoid clobbering partial argument during sibcall References: <550ADF8F.7030300@arm.com> <55314236.2000806@redhat.com> <5534B811.2020107@arm.com> <55353F25.9010906@redhat.com> <55360AA0.9070106@arm.com> <55365A06.7010408@redhat.com> <553689F0.5090606@arm.com> <553E9869.30502@redhat.com> <553F58BB.4070508@foss.arm.com> In-Reply-To: <553F58BB.4070508@foss.arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2015-05/txt/msg00093.txt.bz2 On 04/28/2015 03:54 AM, Kyrill Tkachov wrote: > > On 27/04/15 21:13, Jeff Law wrote: >> On 04/21/2015 11:33 AM, Kyrill Tkachov wrote: >>> On 21/04/15 15:09, Jeff Law wrote: >>>> On 04/21/2015 02:30 AM, Kyrill Tkachov wrote: >>>>> From reading config/stormy16/stormy-abi it seems to me that we >>>>> don't >>>>> pass arguments partially in stormy16, so this code would never be >>>>> called >>>>> there. That leaves pa as the potential problematic target. >>>>> I don't suppose there's an easy way to test on pa? My checkout of >>>>> binutils >>>>> doesn't seem to include a sim target for it. >>>> No simulator, no machines in the testfarm, the box I had access to via >>>> parisc-linux.org seems dead and my ancient PA overheats well before a >>>> bootstrap could complete. I often regret knowing about the backwards >>>> way many things were done on the PA because it makes me think about >>>> cases that only matter on dead architectures. >>> So what should be the action plan here? I can't add an assert on >>> positive result as a negative result is valid. >>> >>> We want to catch the case where this would cause trouble on >>> pa, or change the patch until we're confident that it's fine >>> for pa. >>> >>> That being said, reading the documentation of STACK_GROWS_UPWARD >>> and ARGS_GROW_DOWNWARD I'm having a hard time visualising a case >>> where this would cause trouble on pa. >>> >>> Is the problem that in the function: >>> >>> +/* Add SIZE to X and check whether it's greater than Y. >>> + If it is, return the constant amount by which it's greater or >>> smaller. >>> + If the two are not statically comparable (for example, X and Y >>> contain >>> + different registers) return -1. This is used in expand_push_insn to >>> + figure out if reading SIZE bytes from location X will end up reading >>> from >>> + location Y. */ >>> +static int >>> +memory_load_overlap (rtx x, rtx y, HOST_WIDE_INT size) >>> +{ >>> + rtx tmp = plus_constant (Pmode, x, size); >>> + rtx sub = simplify_gen_binary (MINUS, Pmode, tmp, y); >>> + >>> + if (!CONST_INT_P (sub)) >>> + return -1; >>> + >>> + return INTVAL (sub); >>> +} >>> >>> for ARGS_GROW_DOWNWARD we would be reading 'backwards' from x, >>> so the function should something like the following? >> So I had to go back and compile some simple examples. >> >> References to outgoing arguments will be SP relative. References to the >> incoming arguments will be ARGP relative. And that brings me to the >> another issue. Isn't X in this context the incoming argument slot and >> the destination an outgoing argument slot? >> >> If so, the approach of memory_load_overlap simply won't work on a target >> with calling conventions like the PA. And you might really want to >> consider punting for these kind of calling conventions > > Ok, thanks for the guidance. > How about this? This patch disables sibcall optimisation when > encountering a partial argument when ARGS_GROW_DOWNWARD && > !STACK_GROWS_DOWNWARD. > Hopefully this shouldn't harm codegen on parisc if, as you say, it's > rare to have > partial arguments anyway on PA due to the large number of argument regs. > > I tested this on arm and bootstrapped on x86_64. > I am now going through the process of getting access to a Debian PA > machine to > give it a test there (thanks Dave!) > > Ok if testing comes clean? > > Thanks, > Kyrill > > 2015-04-28 Kyrylo Tkachov > > PR target/65358 > * calls.c (expand_call): Cancel sibcall optimisation when encountering > partial argument on targets with ARGS_GROW_DOWNWARD and > !STACK_GROWS_DOWNWARD. > * expr.c (memory_load_overlap): New function. > (emit_push_insn): When pushing partial args to the stack would > clobber the register part load the overlapping part into a pseudo > and put it into the hard reg after pushing. > > 2015-04-28 Honggyu Kim > > PR target/65358 > * gcc.dg/pr65358.c: New test. The more I think about this, the more I think it's an ugly can of worms and maybe we should just disable sibcalls for partial arguments. I doubt it's a big performance issue in general. In addition to the argument/stack direction stuff, I've been pondering the stack/frame/arg pointer issues. Your approach assumes that the incoming and outgoing areas are always referenced off the same base register. If they aren't, then the routine returns no overlap. But we'd need to consider the case where we have a reference to the arg or frame pointer which later gets rewritten into a stack pointer relative address. Is it too late at the point were you do the checks to reject the sibling call? If not, then maybe the overlap routine should return a tri-state. No overlap, overlap, don't know. The last would be used when the two addresses use a different register. Jeff