public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Uros Bizjak <ubizjak@gmail.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: gcc-patches@gcc.gnu.org, Jakub Jelinek <jakub@redhat.com>
Subject: Re: PATCH: PR target/40838: gcc shouldn't assume that the stack is  	aligned
Date: Thu, 15 Oct 2009 19:53:00 -0000	[thread overview]
Message-ID: <4AD77D3A.2040502@gmail.com> (raw)
In-Reply-To: <6dc9ffc80910151232t20f3fbbfw97b063a0ab33c5ce@mail.gmail.com>

On 10/15/2009 09:32 PM, H.J. Lu wrote:
>>>> We should use PREFERRED_STACK_BOUNDARY_DEFAULT instead of hardcoded 128
>>>> here. At least the comment for P_S_B_D says:
>>>>
>>>> /* It should be MIN_STACK_BOUNDARY. �But we set it to 128 bits for
>>>> � both 32bit and 64bit, to support codes that need 128 bit stack
>>>> � alignment for SSE instructions, but can't realign the stack. �*/
>>>> #define PREFERRED_STACK_BOUNDARY_DEFAULT 128
>>>>
>>>>          
>>> In forced_stack_alignment, we collect the hard alignment requirement
>>> on stack. The decision if stack should be aligned depends on the
>>> incoming stack alignment and the hard stack alignment. It is separate
>>> from PREFERRED_STACK_BOUNDARY_DEFAULT.
>>>
>>>
>>>        
>>>> OTOH, I think that this whole stuff should depend on -mstackrealing
>>>> somehow,
>>>> according to the comment:
>>>>
>>>> /* 1 if -mstackrealign should be turned on by default. �It will
>>>> � generate an alternate prologue and epilogue that realigns the
>>>> � runtime stack if nessary. �This supports mixing codes that keep a
>>>> � 4-byte aligned stack, as specified by i386 psABI, with codes that
>>>> � need a 16-byte aligned stack, as required by SSE instructions. �If
>>>> � STACK_REALIGN_DEFAULT is 1 and PREFERRED_STACK_BOUNDARY_DEFAULT is
>>>> � 128, stacks for all functions may be realigned. �*/
>>>> #define STACK_REALIGN_DEFAULT 0
>>>>
>>>> As far as I understand from many comments from the PR40838 trail
>>>> (especially
>>>> comment #51), -mstackrealing is not effective in some cases involving
>>>> automatic SSE variables on the stack. I think that -mstackrealign should
>>>> be
>>>> fixed in the way your patch outlines, so old/broken sources that assume
>>>> 4byte alignment can be compiled using this option without penalizing
>>>> new/fixed code that assumes 16byte alignment.
>>>>
>>>>
>>>>          
>>> -mstackrealign is very effective. If we turn it on by default, it works
>>> fine:
>>>
>>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40838#c45
>>>
>>> It is just that we don't want to make it the default since we will realign
>>> the stack for almost all functions. In most cases, misaligned stack won't
>>> cause any problems.
>>>
>>> What my patch does is to assume 4byte incoming stack alignment
>>> for functions containing SSE instructions which require hard 16byte
>>> stack alignment.
>>>
>>> After my patch is applied, we can update -mstackrealign to make it an
>>> no-op since all the problems it tries to solve:
>>>
>>> http://gcc.gnu.org/ml/gcc-patches/2006-02/msg00854.html
>>> http://gcc.gnu.org/ml/gcc-patches/2006-05/msg00526.html
>>>
>>> disappeared with my patch.
>>>
>>>        
>> Then we should do realignment the other way around: instead of using
>> -mstackrealing for all the code (including where it has no effect), let's
>> use -mstackrealign to activate realignment functionality that is introduced
>> by your patch.
>>      
> That defeats the whole purpose of my patch, which automatically
> realigns the stack when there is a hard alignment requirement. If it
> isn't turned on by default, it is not very useful.
>
>    
>> IOW, lightweight -mstackrealign, firing up only when there is the
>> possibility of unaligned access in the code it precedes.
>>
>>      
> That is what my patch does, but turned it on by default.
>    

I think that we have the same situation here as was with the infamous 
-mcld option. A specific functionality is needed for compatibility with 
some [broken] code and this functionality has non-negligible impact on 
the performance. AFAICS, there will always be opinions for this 
functionality as well as opinions against it.

I propose that we implement new option -mhard-stackrealign [we can 
bikeshed about this option name a bit ;) ] with corresponding 
--enable-hard-stackrealign as a configure option. This way, both groups 
can have whatever they prefer - compatibility vs. performance.

Looking at -mcld discussions, is this acceptable solution?

Uros.

  parent reply	other threads:[~2009-10-15 19:51 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-06 21:42 H.J. Lu
2009-08-06 22:26 ` Jakub Jelinek
2009-08-06 22:52   ` H.J. Lu
2009-10-15 15:58 ` H.J. Lu
2009-10-15 18:45   ` Uros Bizjak
2009-10-15 19:22     ` H.J. Lu
2009-10-15 19:32       ` Uros Bizjak
2009-10-15 19:43         ` H.J. Lu
2009-10-15 19:48           ` Jakub Jelinek
2009-10-15 20:11             ` H.J. Lu
2009-10-15 19:53           ` Uros Bizjak [this message]
2009-10-15 21:01             ` H.J. Lu
2009-10-15 21:41               ` Uros Bizjak
2009-10-16 20:27     ` H.J. Lu
2009-10-17  1:03       ` Ian Lance Taylor
2009-10-17 18:22         ` H.J. Lu
2009-10-17 19:02           ` Richard Guenther
2009-10-17 19:21             ` H.J. Lu
2009-10-17 19:29               ` Richard Guenther
2009-10-17 19:35                 ` H.J. Lu
2009-10-17 19:46                   ` Richard Guenther
2009-10-17 20:01                     ` H.J. Lu
2009-10-17 20:59                       ` Richard Guenther
2009-10-18 19:21                         ` Michael Matz
2009-10-18 19:45                           ` Richard Guenther
2009-10-19 16:36                             ` H.J. Lu
2009-10-20  1:12                               ` Michael Matz
2009-10-20 19:10                                 ` H.J. Lu
2009-10-19 16:38                           ` H.J. Lu
2009-10-19 17:08                             ` Ian Lance Taylor
2009-10-19 17:26                               ` H.J. Lu
2009-10-19 17:33                                 ` Ian Lance Taylor
2009-10-19 17:46                                   ` H.J. Lu
2009-10-19 17:55                                     ` Ian Lance Taylor
2009-10-19 19:16                                       ` H.J. Lu
2009-10-19 21:15                                         ` Ian Lance Taylor
2009-10-20 19:00                                           ` H.J. Lu
2009-10-20  1:23                                         ` Michael Matz
2009-10-20 19:12                                           ` H.J. Lu
2009-10-20  1:53                             ` Michael Matz
2009-10-20 21:15                               ` H.J. Lu
2009-10-21  1:10                                 ` H.J. Lu
2009-10-21  9:54                                   ` Michael Matz
2009-10-21 16:56                                     ` H.J. Lu
2009-10-30 10:08                                       ` Richard Guenther
2009-10-17  7:09       ` Uros Bizjak
2009-08-07  0:54 Mikulas Patocka
2009-08-07  7:13 ` Jakub Jelinek
2009-08-07 12:53   ` H.J. Lu
2009-08-07 22:30     ` H.J. Lu
2009-08-08 17:35       ` Mikulas Patocka
2009-08-16 21:25         ` H.J. Lu
2009-08-24 17:39       ` H.J. Lu
2009-09-12 23:32         ` Mikulas Patocka
2009-09-12 23:42           ` Mikulas Patocka
2009-09-13  1:55           ` H.J. Lu
2009-09-13 14:10             ` Mikulas Patocka
2009-08-07 21:08   ` Mikulas Patocka
2009-08-07 21:25     ` Richard Guenther

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=4AD77D3A.2040502@gmail.com \
    --to=ubizjak@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hjl.tools@gmail.com \
    --cc=jakub@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).