public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
To: Jeff Law <law@redhat.com>
Cc: gcc-patches@gcc.gnu.org, Andreas Krebbel <krebbel@linux.vnet.ibm.com>
Subject: Re: [PATCH 2/2][v3] Drop excess size used for run time allocated stack variables.
Date: Fri, 22 Jul 2016 12:02:00 -0000	[thread overview]
Message-ID: <20160722095522.GA24126@linux.vnet.ibm.com> (raw)
In-Reply-To: <59557a2d-0a6c-46d5-8e0a-02b7845c8734@redhat.com>

On Thu, Jul 21, 2016 at 02:07:05PM -0600, Jeff Law wrote:
> On 06/23/2016 03:57 AM, Dominik Vogt wrote:
> >>and use that rather than rounding size up to an alignment boundary.
> >
> >Not exactly.  Consider the unpatched code.  At the beginning we
> >have some amount of space to be allocated on the stack at runtime
> >("SSIZE"), some requested alignment for it ("SALIGN").
> >
> >get_dynamic_stack_size() first calculates the space needed for run
> >time alignment:
> >
> >  SIZE = SSIZE + SALIGN - 1
> >
> >Then it calls round_push() to add *another* chunk of memory to the
> >allocation size to be able to align it to the required stack slot
> >alignment ("SLOTALIGN") at run time.
> >
> >  SIZE = SIZE + SLOTALIGN - 1
> >       = SSIZE + (SALIGN - 1) + (SLOTALIGN - 1)
> >
> >Now it has added two chunks of memory but alignment is only done
> >once.  With the patch it just adds the maximum of (SALIGN - 1) and
> >(SLOTALIGN - 1), not both.  Thinking about it, the "round_push"
> >stuff is a very complicated way of saying "add max(A, B)".
> Now I see it.  Thanks, that helped a ton.
> 
> >
> >I'd volunteer to clean this up more, but preferrably when the two
> >pending patches are in.  The current code is a real brain-twister.
> I'd be all for such cleanups after we wrap up the pending patches.
> It's certainly a rats nest of code right now.
> 
> This patch is fine for the trunk.  Thanks for your patience.

Actually I was goind to abandon the patch in its current state.
:-)  We talked about it internally and concluded that the problem
is really this:

 * get_dynamic_stack_size is passed a SIZE of a data block (which
   is allocated elsewhere), the SIZE_ALIGN of the SIZE (i.e. the
   alignment of the underlying memory units (e.g. 32 bytes split
   into 4 times 8 bytes = 64 bit alignment) and the
   REQUIRED_ALIGN of the data portion of the allocated memory.
 * Assuming the function is called with SIZE = 2, SIZE_ALIGN = 8
   and REQUIRED_ALIGN = 64 it first adds 7 bytes to SIZE -> 9.
   This is what is needed to have two bytes 8-byte-aligned at some
   memory location without any known alignment.
 * Finally round_push is called to round up SIZE to a multiple of
   the stack slot size.

The key to understanding this is that the function assumes that
STACK_DYNMAIC_OFFSET is completely unknown at the time its called
and therefore it does not make assumptions about the alignment of
STACKPOINTER + STACK_DYNMAIC_OFFSET.  The latest patch simply
hard-codes that SP + SDO is supposed to be aligned to at least
stack slot size (and does that in a very complicated way).  Since
there is no guarantee that this is the case on all targets, the
patch is broken.  It may miscalculate a SIZE that is too small in
some cases.

However, on many targets there is some guarantee about the
alignment of SP + SDO even if the actual value of SDO is unknown.
On s390x it's always 8-byte-aligned (stack slot size).  So the
right fix should be to add knowledge about the target's guaranteed
alignment of SP + SDO to the function.  I'm right now testing a
much simpler patch that uses
REGNO_POINTER_ALIGN(VIRTUAL_STACK_DYNAMIC_REGNUM) as the
alignment.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

  reply	other threads:[~2016-07-22 12:02 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-29 22:13 [PATCH] " Dominik Vogt
2016-04-29 22:15 ` Dominik Vogt
2016-04-30  9:44 ` Eric Botcazou
2016-04-30 10:14   ` Dominik Vogt
2016-05-02 13:43 ` Dominik Vogt
2016-05-02 15:10 ` Jeff Law
2016-05-03 14:18   ` Dominik Vogt
2016-05-19 23:11     ` Jeff Law
2016-05-20 21:24       ` [RFA] Minor cleanup to allocate_dynamic_stack_space Jeff Law
2016-05-20 21:44         ` Eric Botcazou
2016-05-20 21:48           ` Jeff Law
2016-05-23  7:53             ` Eric Botcazou
2016-05-23 10:12         ` Dominik Vogt
2016-05-25 12:46         ` Dominik Vogt
2016-06-09 12:00       ` [PATCH] Drop excess size used for run time allocated stack variables Bernd Schmidt
2016-06-21  9:35         ` Dominik Vogt
2016-06-21 22:26           ` Jeff Law
2016-06-22  8:57             ` Dominik Vogt
2016-05-25 14:02     ` [PATCH 1/2][v3] " Dominik Vogt
2016-05-25 14:31       ` [PATCH 2/2][v3] " Dominik Vogt
2016-05-25 14:51         ` Dominik Vogt
2016-06-08 11:21         ` Bernd Schmidt
2016-06-20 12:20           ` Dominik Vogt
2016-06-20 12:20             ` Bernd Schmidt
2016-06-23  4:24         ` Jeff Law
2016-06-23  9:57           ` Dominik Vogt
2016-07-21 20:07             ` Jeff Law
2016-07-22 12:02               ` Dominik Vogt [this message]
2016-07-26 15:53                 ` [PATCH 2/2][v4] " Dominik Vogt
2016-08-18 16:20                   ` Jeff Law
2016-08-23  9:23                   ` Andreas Krebbel
2016-06-08 11:20       ` [PATCH 1/2][v3] " Bernd Schmidt
2016-06-08 12:20         ` Eric Botcazou
2016-06-22 20:34       ` Jeff Law
2016-07-04 14:22       ` Andreas Krebbel

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=20160722095522.GA24126@linux.vnet.ibm.com \
    --to=vogt@linux.vnet.ibm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=krebbel@linux.vnet.ibm.com \
    --cc=law@redhat.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).