public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: Kyrill Tkachov <kyrylo.tkachov@foss.arm.com>,
	       GCC Patches <gcc-patches@gcc.gnu.org>
Cc: Honggyu Kim <hong.gyu.kim@lge.com>
Subject: Re: [PATCH][expr.c] PR 65358 Avoid clobbering partial argument during sibcall
Date: Tue, 12 May 2015 22:12:00 -0000	[thread overview]
Message-ID: <555278FE.90603@redhat.com> (raw)
In-Reply-To: <5550764C.1070502@foss.arm.com>

On 05/11/2015 03:28 AM, Kyrill Tkachov wrote:
>> 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.
>
> We already have quite a bit of code in calls.c to detect cases with
> partial argument overlap for the
> explicit purpose of allowing sibcalls when partial arguments occur in
> the general case. However, that
> code only detects when a partial argument overlaps with other arguments
> in a call. In this PR the
> partial argument overlaps with itself. It would be a shame to disable
> sibcalls for all partial arguments
> when there is already infrastructure in place to handle them.
I didn't even realize we had support for partial arguments in sibcalls. 
   Ah, Kazu added that in 2005, I totally missed it.  I probably would 
have suggested failing the sibcall for those cases back then too...

Is there any way to re-use that infrastructure to deal with the case at 
hand?



>
>>
>>
>> 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.
>
> Ok, here is my attempt at that. The overlap functions returns -2 when it
> cannot staticall compare the
> two pointers (i.e. when the base registers are different) and the caller
> then disables sibcalls.
> The code in calls.c that calls this code will undo any emitted
> instructions in the meantime if sibcall
> optimisation fails. This required me to change the type of
> emit_push_insn to bool and add an extra
> parameter, so this patch touches a bit more code than the original version.
>
> Bootstrapped on x86_64 and tested on arm. The testcase in this PR still
> performs a sibcall correctly on arm.
>
> What do you think of this?
>
> Thanks,
> Kyrill
>
>
> 2015-05-11  Kyrylo Tkachov <kyrylo.tkachov@arm.com>
>
>      PR target/65358
>      * 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.  Change return type
>      to bool.  Add bool argument.
>      * expr.h (emit_push_insn): Change return type to bool.
>      Add bool argument.
>      * calls.c (expand_call): Cancel sibcall optimisation when encountering
>      partial argument on targets with ARGS_GROW_DOWNWARD and
>      !STACK_GROWS_DOWNWARD.
>      (emit_library_call_value_1): Update callsite of emit_push_insn.
>      (store_one_arg): Likewise.
>
>
> 2015-05-11  Honggyu Kim <hong.gyu.kim@lge.com>
>
>      PR target/65358
>      * gcc.dg/pr65358.c: New test.
>
>>
>> Jeff
>>
>>
>
>
> expr.patch
>
>
> commit 5b596f10846b6d3b143442a306801c8262d8b10a
> Author: Kyrylo Tkachov<kyrylo.tkachov@arm.com>
> Date:   Wed Mar 18 13:42:37 2015 +0000
>
>      [expr.c] PR 65358 Avoid clobbering partial argument during sibcall
>
> diff --git a/gcc/calls.c b/gcc/calls.c
> index caa7d60..81ef2c9 100644
> --- a/gcc/calls.c
> +++ b/gcc/calls.c
> @@ -3225,6 +3225,13 @@ expand_call (tree exp, rtx target, int ignore)
>   	    {
>   	      rtx_insn *before_arg = get_last_insn ();
>
> +	     /* On targets with weird calling conventions (e.g. PA) it's
> +		hard to ensure that all cases of argument overlap between
> +		stack and registers work.  Play it safe and bail out.  */
> +#if defined (ARGS_GROW_DOWNWARD) && !defined (STACK_GROWS_DOWNWARD)
> +	      sibcall_failure = 1;
> +	      break;
> +#endif
So we're trying to get away from this kind of conditional compilation.

Instead we want to write

if (ARGS_GROW_DOWNWARD && !STACK_GROWS_DOWNWARD)

ARGS_GROW_DOWNWARD is already a testable value.  But 
STACK_GROWS_DOWNWARD is not.  The way folks have been dealing with this 
is something like this after the #includes:

/* Redefine STACK_GROWS_DOWNWARD in terms of 0 or 1.  */
#ifdef STACK_GROWS_DOWNWARD
# undef STACK_GROWS_DOWNWARD
# define STACK_GROWS_DOWNWARD 1
#else
# define STACK_GROWS_DOWNWARD 0
#endif


With that in place you can change the test into the more desirable
if (ARGS_GROW_DOWNWARD && !STACK_GROWS_DOWNWARD)



> diff --git a/gcc/expr.c b/gcc/expr.c
> index 25aa11f..712fa0b 100644
> --- a/gcc/expr.c
> +++ b/gcc/expr.c
> @@ -4121,12 +4121,35 @@ emit_single_push_insn (machine_mode mode, rtx x, tree type)
>   }
>   #endif
>
> +/* If reading SIZE bytes from X will end up reading from
> +   Y return the number of bytes that overlap.  Return -1
> +   if there is no overlap or -2 if we can't determing
s/determing/determine/

> +   partial argument during a sibcall optimisation (as specified by
s/optimisation/optimization/


I guess I'm still not real comfortable that we've got the issues here 
resolved and if we're going to try and support this case, then re-using 
the existing infrastructure would be better.

I'll approve with the changes noted above, but would ask that you look 
into trying to re-use the existing infrastructure as a follow-up.

Jeff


  reply	other threads:[~2015-05-12 22:04 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-19 14:39 Kyrill Tkachov
2015-03-27 10:06 ` Kyrill Tkachov
2015-03-29 11:29 ` Honggyu Kim
2015-04-13 14:01 ` Kyrill Tkachov
2015-04-13 16:33   ` Jeff Law
2015-04-17 17:26 ` Jeff Law
2015-04-20  8:25   ` Kyrill Tkachov
2015-04-20 18:02     ` Jeff Law
2015-04-21  8:30       ` Kyrill Tkachov
2015-04-21 14:09         ` Jeff Law
2015-04-21 17:33           ` Kyrill Tkachov
2015-04-22 11:51             ` Kyrill Tkachov
2015-04-27 10:12               ` Kyrill Tkachov
2015-04-27 13:16                 ` John David Anglin
2015-05-06 18:57                   ` John David Anglin
2015-04-27 20:13             ` Jeff Law
2015-04-28 10:19               ` Kyrill Tkachov
2015-04-30 12:09                 ` Kyrill Tkachov
2015-05-01 18:51                 ` Jeff Law
2015-05-11  9:28                   ` Kyrill Tkachov
2015-05-12 22:12                     ` Jeff Law [this message]
2015-05-27 14:00                       ` Kyrill Tkachov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=555278FE.90603@redhat.com \
    --to=law@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hong.gyu.kim@lge.com \
    --cc=kyrylo.tkachov@foss.arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).