public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64
@ 2012-05-17  0:19 hpa at zytor dot com
  2012-05-17 14:12 ` [Bug target/53383] " hjl.tools at gmail dot com
                   ` (24 more replies)
  0 siblings, 25 replies; 27+ messages in thread
From: hpa at zytor dot com @ 2012-05-17  0:19 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

             Bug #: 53383
           Summary: Allow -mpreferred-stack-boundary=3 on x86-64
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: hpa@zytor.com


In the Linux kernel, we do not use SSE or floating-point of any kind (except in
very particular highly controlled places); furthermore, stack space is at an
extreme premium.  As such, it makes absolutely no sense to align the stack to
16 bytes in x86-64.

gcc, however, refuses to allow setting the stack alignment to 8 bytes:

: anacreon 105 ; gcc -mpreferred-stack-boundary=3 -mincoming-stack-boundary=3
-O2 -mno-sse -c /tmp/foo.c
/tmp/foo.c:1:0: error: -mpreferred-stack-boundary=3 is not between 4 and 12
/tmp/foo.c:1:0: error: -mincoming-stack-boundary=3 is not between 4 and 12

This is particularly ironic since we have found out that, in fact, ALL kernel
stacks are actually 16-byte misaligned on x86-64 as the entry code pushes a
total of 88 bytes onto the stack.  As such, gcc trying to keep a 16-byte
alignment actually makes the code do worse, not better.


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
@ 2012-05-17 14:12 ` hjl.tools at gmail dot com
  2012-05-17 14:29 ` hpa at zytor dot com
                   ` (23 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hjl.tools at gmail dot com @ 2012-05-17 14:12 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hjl.tools at gmail dot com,
                   |                            |ubizjak at gmail dot com

--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> 2012-05-17 14:00:14 UTC ---
I think we can relax it under -mcmodel=kernel.


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
  2012-05-17 14:12 ` [Bug target/53383] " hjl.tools at gmail dot com
@ 2012-05-17 14:29 ` hpa at zytor dot com
  2012-05-17 15:44 ` hjl.tools at gmail dot com
                   ` (22 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hpa at zytor dot com @ 2012-05-17 14:29 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

--- Comment #2 from H. Peter Anvin <hpa at zytor dot com> 2012-05-17 14:11:23 UTC ---
Why would -mcmodel=kernel matter for this?  (For the record, there is C code in
the Linux kernel which doesn't use -mcmodel=kernel, too, and other embedded
programs may very well have the same issue.)


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
  2012-05-17 14:12 ` [Bug target/53383] " hjl.tools at gmail dot com
  2012-05-17 14:29 ` hpa at zytor dot com
@ 2012-05-17 15:44 ` hjl.tools at gmail dot com
  2012-05-17 16:00 ` hpa at zytor dot com
                   ` (21 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hjl.tools at gmail dot com @ 2012-05-17 15:44 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> 2012-05-17 15:37:02 UTC ---
Following the x86-64 psABI, GCC assumes incoming stack is
16byte aligned and generates 16-byte aligned vector move
on stack.  If it isn't true, you will get segfault at
run-time.


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (2 preceding siblings ...)
  2012-05-17 15:44 ` hjl.tools at gmail dot com
@ 2012-05-17 16:00 ` hpa at zytor dot com
  2012-05-17 16:28 ` hpa at zytor dot com
                   ` (20 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hpa at zytor dot com @ 2012-05-17 16:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

--- Comment #4 from H. Peter Anvin <hpa at zytor dot com> 2012-05-17 15:59:28 UTC ---
Only if the program in question is actually using SSE.  If SSE is disallowed
(because it is kernel code, or some other embedded piece of code) it is
irrelevant.


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (3 preceding siblings ...)
  2012-05-17 16:00 ` hpa at zytor dot com
@ 2012-05-17 16:28 ` hpa at zytor dot com
  2012-05-18 11:41 ` rguenth at gcc dot gnu.org
                   ` (19 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hpa at zytor dot com @ 2012-05-17 16:28 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

--- Comment #5 from H. Peter Anvin <hpa at zytor dot com> 2012-05-17 16:09:19 UTC ---
The point is that the key is -mno-sse, not -mcmodel=kernel.


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (4 preceding siblings ...)
  2012-05-17 16:28 ` hpa at zytor dot com
@ 2012-05-18 11:41 ` rguenth at gcc dot gnu.org
  2012-05-18 12:02 ` hubicka at gcc dot gnu.org
                   ` (18 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-05-18 11:41 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-05-18
     Ever Confirmed|0                           |1


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (5 preceding siblings ...)
  2012-05-18 11:41 ` rguenth at gcc dot gnu.org
@ 2012-05-18 12:02 ` hubicka at gcc dot gnu.org
  2012-05-18 17:29 ` hpa at zytor dot com
                   ` (17 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hubicka at gcc dot gnu.org @ 2012-05-18 12:02 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

Jan Hubicka <hubicka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hubicka at gcc dot gnu.org

--- Comment #6 from Jan Hubicka <hubicka at gcc dot gnu.org> 2012-05-18 11:54:03 UTC ---
The reason why -mpreferred-stack-boundary=3 is not allowed is that the va-args
sequences generated are not safe in the case frame is misaligned and values
with higher intended alignment are passed.
In that case the caller would be required to do dynamic stack alignment. 

Otherwise the value might end up misaligned on the stack and va-arg sequence
will do alignment using & operation resulting in fetching wrong value from
memory.
Since we have dynamic stack alignment now, we could allow that and explicitely
document that as ABI breaking (like we have the double alignment and other
kludges on x86)

Honza


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (6 preceding siblings ...)
  2012-05-18 12:02 ` hubicka at gcc dot gnu.org
@ 2012-05-18 17:29 ` hpa at zytor dot com
  2012-05-19 19:22 ` hubicka at ucw dot cz
                   ` (16 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hpa at zytor dot com @ 2012-05-18 17:29 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

--- Comment #7 from H. Peter Anvin <hpa at zytor dot com> 2012-05-18 15:23:05 UTC ---
We can't use the SSE parts of the ABI anyway in the kernel, and I sure hope
that -mno-sse (or perhaps -mcmodel=kernel, but that would be ugly) prevents
those from being generated.

Yes, it's an ABI violation, but it's a very necessary one...


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (7 preceding siblings ...)
  2012-05-18 17:29 ` hpa at zytor dot com
@ 2012-05-19 19:22 ` hubicka at ucw dot cz
  2012-05-19 21:28 ` hjl.tools at gmail dot com
                   ` (15 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hubicka at ucw dot cz @ 2012-05-19 19:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

--- Comment #8 from Jan Hubicka <hubicka at ucw dot cz> 2012-05-19 19:14:18 UTC ---
__int128 do not require SSE and yet it is 128bit aligned....
I am not against allowing smaller alignments, we just need to document it
breaks ABI and it would be nice to explain how
(and probably warn on 128bit aligned varargs or force the dynamc alignment)


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (8 preceding siblings ...)
  2012-05-19 19:22 ` hubicka at ucw dot cz
@ 2012-05-19 21:28 ` hjl.tools at gmail dot com
  2012-05-19 21:54 ` hubicka at ucw dot cz
                   ` (14 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hjl.tools at gmail dot com @ 2012-05-19 21:28 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

--- Comment #9 from H.J. Lu <hjl.tools at gmail dot com> 2012-05-19 21:03:10 UTC ---
With this patch:

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index eca542c..3e4e768 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -3660,9 +3660,14 @@ ix86_option_override_internal (bool main_args_p)
   ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT;
   if (global_options_set.x_ix86_preferred_stack_boundary_arg)
     {
-      int min = (TARGET_64BIT ? 4 : 2);
+      int min;
       int max = (TARGET_SEH ? 4 : 12);

+      if (TARGET_64BIT)
+    min = TARGET_SSE ? 4 : 3;
+      else
+    min = 2;
+
       if (ix86_preferred_stack_boundary_arg < min
       || ix86_preferred_stack_boundary_arg > max)
     {
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index ddb3645..f7f13d2 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -708,7 +708,7 @@ enum target_cpu_default
 #define MAIN_STACK_BOUNDARY (TARGET_64BIT ? 128 : 32)

 /* Minimum stack boundary.  */
-#define MIN_STACK_BOUNDARY (TARGET_64BIT ? 128 : 32)
+#define MIN_STACK_BOUNDARY (TARGET_64BIT ? (TARGET_SSE ? 128 : 64) : 32)

 /* Boundary (in *bits*) on which the stack pointer prefers to be
    aligned; the compiler cannot rely on having this alignment.  */

I got

[hjl@gnu-mic-2 gcc]$ cat /tmp/x.c
extern __int128 x;

extern void bar (int, int, int, int, int, __int128);
void
foo (void)
{
  bar (1, 2, 3, 4, 5, x);
}
[hjl@gnu-mic-2 gcc]$ ./xgcc -B./ -S -O2 /tmp/x.c -mpreferred-stack-boundary=3 
-mno-sse
[hjl@gnu-mic-2 gcc]$ cat x.s
    .file    "x.c"
    .text
    .p2align 4,,15
    .globl    foo
    .type    foo, @function
foo:
.LFB0:
    .cfi_startproc
    pushq    %rbp
    .cfi_def_cfa_offset 16
    .cfi_offset 6, -16
    movl    $5, %r8d
    movl    $4, %ecx
    movl    $2, %esi
    movl    $1, %edi
    movq    %rsp, %rbp
    .cfi_def_cfa_register 6
    andq    $-16, %rsp
    subq    $16, %rsp
    movq    x+8(%rip), %rdx
    movq    x(%rip), %rax
    movq    %rdx, 8(%rsp)
    movq    %rax, (%rsp)
    movl    $3, %edx
    call    bar
    leave
    .cfi_def_cfa 7, 8
    ret
    .cfi_endproc
.LFE0:
    .size    foo, .-foo
    .ident    "GCC: (GNU) 4.8.0 20120519 (experimental)"
    .section    .note.GNU-stack,"",@progbits
[hjl@gnu-mic-2 gcc]$ 

It looks OK to me.


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (9 preceding siblings ...)
  2012-05-19 21:28 ` hjl.tools at gmail dot com
@ 2012-05-19 21:54 ` hubicka at ucw dot cz
  2012-05-20  4:45 ` hjl.tools at gmail dot com
                   ` (13 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hubicka at ucw dot cz @ 2012-05-19 21:54 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

--- Comment #10 from Jan Hubicka <hubicka at ucw dot cz> 2012-05-19 21:47:39 UTC ---
The problem is va_args doing alignment based on stack pointer, i.e. in:
int
test (int a, ...)
{
  va_list p;

  va_start (p, a);
    va_arg (p, int);
    va_arg (p, int);
    va_arg (p, int);
    va_arg (p, int);
    va_arg (p, int);
    va_arg (p, int);
    va_arg (p, int);
    va_arg (p, int);
    va_arg (p, int);
    va_arg (p, int);
  if (a) 
    va_arg (p, int);
  return va_arg (p, __int128);
}

test:
.LFB0:
        .cfi_startproc
        leaq    8(%rsp), %rax
        movq    %rdx, -40(%rsp)
        movq    %rsi, -48(%rsp)
        movq    %rcx, -32(%rsp)
        movq    %r8, -24(%rsp)
        movq    %rax, -72(%rsp)
        leaq    -56(%rsp), %rax
        addq    $8, -72(%rsp)
        testl   %edi, %edi
        movq    %r9, -16(%rsp)
        movl    $48, -80(%rsp)
        movq    %rax, -64(%rsp)
        movq    -72(%rsp), %rax
        leaq    32(%rax), %rdx
        movq    %rdx, -72(%rsp)
        je      .L14
        addq    $40, %rax
        movq    %rax, -72(%rsp)
.L14:
        movq    -72(%rsp), %rax
        addq    $15, %rax
        andq    $-16, %rax
        leaq    16(%rax), %rdx
        movq    %rdx, -72(%rsp)
        movq    (%rax), %rax
        ret
        .cfi_endproc
.LFE0:

this will get out of sync with hard coded offsets if rsp hapepns to be
misaligned.


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (10 preceding siblings ...)
  2012-05-19 21:54 ` hubicka at ucw dot cz
@ 2012-05-20  4:45 ` hjl.tools at gmail dot com
  2012-05-20 11:15 ` hubicka at ucw dot cz
                   ` (12 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hjl.tools at gmail dot com @ 2012-05-20  4:45 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

--- Comment #11 from H.J. Lu <hjl.tools at gmail dot com> 2012-05-20 02:04:40 UTC ---
(In reply to comment #10)
> The problem is va_args doing alignment based on stack pointer, i.e. in:
> int
>
>   return va_arg (p, __int128);
> }
> 

>         addq    $15, %rax
>         andq    $-16, %rax

This isn't necessary.  If __int128 is put on stack by caller,
the stack must be aligned at 16 bytes.

>         leaq    16(%rax), %rdx
>         movq    %rdx, -72(%rsp)
>         movq    (%rax), %rax
>         ret
>         .cfi_endproc
> .LFE0:
> 
> this will get out of sync with hard coded offsets if rsp hapepns to be
> misaligned.

I don't think it will happen.


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (11 preceding siblings ...)
  2012-05-20  4:45 ` hjl.tools at gmail dot com
@ 2012-05-20 11:15 ` hubicka at ucw dot cz
  2012-05-20 11:35   ` Jan Hubicka
  2012-05-20 13:56 ` hubicka at ucw dot cz
                   ` (11 subsequent siblings)
  24 siblings, 1 reply; 27+ messages in thread
From: hubicka at ucw dot cz @ 2012-05-20 11:15 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

--- Comment #12 from Jan Hubicka <hubicka at ucw dot cz> 2012-05-20 10:15:06 UTC ---
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383
> 
> --- Comment #11 from H.J. Lu <hjl.tools at gmail dot com> 2012-05-20 02:04:40 UTC ---
> (In reply to comment #10)
> > The problem is va_args doing alignment based on stack pointer, i.e. in:
> > int
> >
> >   return va_arg (p, __int128);
> > }
> > 
> 
> >         addq    $15, %rax
> >         andq    $-16, %rax
> 
> This isn't necessary.  If __int128 is put on stack by caller,
> the stack must be aligned at 16 bytes.

Not when you call function with -fpreferred-stack-boundary=3
and it is itself compiled with -fpreferred-stack-boudnary=4
and calls another functions passing __int128.
Thus the ABI incompatibility.
Honza


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-20 11:15 ` hubicka at ucw dot cz
@ 2012-05-20 11:35   ` Jan Hubicka
  0 siblings, 0 replies; 27+ messages in thread
From: Jan Hubicka @ 2012-05-20 11:35 UTC (permalink / raw)
  To: hubicka at ucw dot cz; +Cc: gcc-bugs

> > This isn't necessary.  If __int128 is put on stack by caller,
> > the stack must be aligned at 16 bytes.
> 
> Not when you call function with -fpreferred-stack-boundary=3
> and it is itself compiled with -fpreferred-stack-boudnary=4
> and calls another functions passing __int128.
> Thus the ABI incompatibility.
... and the alignment code is there not to align stack frame, but to
align the __int128bit position within the argument area.  The
va_arg calls beforehand are of unknon count.
> Honza


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (12 preceding siblings ...)
  2012-05-20 11:15 ` hubicka at ucw dot cz
@ 2012-05-20 13:56 ` hubicka at ucw dot cz
  2012-05-20 15:36 ` hjl.tools at gmail dot com
                   ` (10 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hubicka at ucw dot cz @ 2012-05-20 13:56 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

--- Comment #13 from Jan Hubicka <hubicka at ucw dot cz> 2012-05-20 11:34:27 UTC ---
> > This isn't necessary.  If __int128 is put on stack by caller,
> > the stack must be aligned at 16 bytes.
> 
> Not when you call function with -fpreferred-stack-boundary=3
> and it is itself compiled with -fpreferred-stack-boudnary=4
> and calls another functions passing __int128.
> Thus the ABI incompatibility.
... and the alignment code is there not to align stack frame, but to
align the __int128bit position within the argument area.  The
va_arg calls beforehand are of unknon count.
> Honza


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (13 preceding siblings ...)
  2012-05-20 13:56 ` hubicka at ucw dot cz
@ 2012-05-20 15:36 ` hjl.tools at gmail dot com
  2012-05-20 15:39 ` hjl.tools at gmail dot com
                   ` (9 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hjl.tools at gmail dot com @ 2012-05-20 15:36 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

--- Comment #14 from H.J. Lu <hjl.tools at gmail dot com> 2012-05-20 14:28:18 UTC ---
(In reply to comment #12)
> 
> Not when you call function with -fpreferred-stack-boundary=3
> and it is itself compiled with -fpreferred-stack-boudnary=4
> and calls another functions passing __int128.
> Thus the ABI incompatibility.

When everything is compiled with -fpreferred-stack-boundary=3,
it works fine.


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (14 preceding siblings ...)
  2012-05-20 15:36 ` hjl.tools at gmail dot com
@ 2012-05-20 15:39 ` hjl.tools at gmail dot com
  2012-06-22 17:11 ` hjl at gcc dot gnu.org
                   ` (8 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hjl.tools at gmail dot com @ 2012-05-20 15:39 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |http://gcc.gnu.org/ml/gcc-p
                   |                            |atches/2012-05/msg01334.htm
                   |                            |l

--- Comment #15 from H.J. Lu <hjl.tools at gmail dot com> 2012-05-20 14:48:44 UTC ---
A patch is posted at

http://gcc.gnu.org/ml/gcc-patches/2012-05/msg01334.html


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (15 preceding siblings ...)
  2012-05-20 15:39 ` hjl.tools at gmail dot com
@ 2012-06-22 17:11 ` hjl at gcc dot gnu.org
  2012-06-22 17:12 ` hjl.tools at gmail dot com
                   ` (7 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hjl at gcc dot gnu.org @ 2012-06-22 17:11 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

--- Comment #16 from hjl at gcc dot gnu.org <hjl at gcc dot gnu.org> 2012-06-22 17:11:10 UTC ---
Author: hjl
Date: Fri Jun 22 17:10:58 2012
New Revision: 188893

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=188893
Log:
Allow -mpreferred-stack-boundary=3 on x86-64

    PR target/53383
    * doc/invoke.texi: Add a warning for -mpreferred-stack-boundary=3.

    * config/i386/i386.c (ix86_option_override_internal): Allow
    -mpreferred-stack-boundary=3 for 64-bit if SSE is disabled.

    * config/i386/i386.h (MIN_STACK_BOUNDARY): Set to 64 for 64-bit
    if SSE is disabled.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c
    trunk/gcc/config/i386/i386.h
    trunk/gcc/doc/invoke.texi


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (16 preceding siblings ...)
  2012-06-22 17:11 ` hjl at gcc dot gnu.org
@ 2012-06-22 17:12 ` hjl.tools at gmail dot com
  2012-06-22 17:13 ` hjl at gcc dot gnu.org
                   ` (6 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hjl.tools at gmail dot com @ 2012-06-22 17:12 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.8.0

--- Comment #16 from hjl at gcc dot gnu.org <hjl at gcc dot gnu.org> 2012-06-22 17:11:10 UTC ---
Author: hjl
Date: Fri Jun 22 17:10:58 2012
New Revision: 188893

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=188893
Log:
Allow -mpreferred-stack-boundary=3 on x86-64

    PR target/53383
    * doc/invoke.texi: Add a warning for -mpreferred-stack-boundary=3.

    * config/i386/i386.c (ix86_option_override_internal): Allow
    -mpreferred-stack-boundary=3 for 64-bit if SSE is disabled.

    * config/i386/i386.h (MIN_STACK_BOUNDARY): Set to 64 for 64-bit
    if SSE is disabled.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c
    trunk/gcc/config/i386/i386.h
    trunk/gcc/doc/invoke.texi

--- Comment #17 from H.J. Lu <hjl.tools at gmail dot com> 2012-06-22 17:12:14 UTC ---
Fixed for 4.8.0.


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (17 preceding siblings ...)
  2012-06-22 17:12 ` hjl.tools at gmail dot com
@ 2012-06-22 17:13 ` hjl at gcc dot gnu.org
  2013-02-27 10:22 ` paolo.carlini at oracle dot com
                   ` (5 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hjl at gcc dot gnu.org @ 2012-06-22 17:13 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.8.0

--- Comment #17 from H.J. Lu <hjl.tools at gmail dot com> 2012-06-22 17:12:14 UTC ---
Fixed for 4.8.0.


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (18 preceding siblings ...)
  2012-06-22 17:13 ` hjl at gcc dot gnu.org
@ 2013-02-27 10:22 ` paolo.carlini at oracle dot com
  2015-07-05 19:56 ` luto at mit dot edu
                   ` (4 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-02-27 10:22 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ogoffart at kde dot org

--- Comment #18 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-02-27 10:21:37 UTC ---
*** Bug 56464 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (19 preceding siblings ...)
  2013-02-27 10:22 ` paolo.carlini at oracle dot com
@ 2015-07-05 19:56 ` luto at mit dot edu
  2015-07-05 20:36 ` hjl.tools at gmail dot com
                   ` (3 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: luto at mit dot edu @ 2015-07-05 19:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

Andy Lutomirski <luto at mit dot edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |luto at mit dot edu

--- Comment #19 from Andy Lutomirski <luto at mit dot edu> ---
I don't think the fix is correct.

This works:

gcc -mno-sse -mpreferred-stack-boundary=3 ...

This does not:

gcc -mno-sse -mpreferred-stack-boundary=3 -mincoming-stack-boundary=3 ...

This makes no sense, since they should be equivalent.

Also, I find the docs to be unclear as to what different values of the incoming
and preferred stack boundaries mean.

Finally, why is -mno-sse required in order to set a low stack boundary? 
Couldn't gcc figure out that the existence of a stack variable (SSE, alignas,
__attribute__((aligned(32))), etc) should force dynamic stack alignment?  In
fact, that should be necessary, and already appears to work, for
__attribute__((aligned(32))), as gcc generates correct code for this:

typedef int __attribute__((aligned(32))) int_aligned_32;

extern void func2(int_aligned_32 *x);

void func(void)
{
        int_aligned_32 x;
        func2(&x);
}


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (20 preceding siblings ...)
  2015-07-05 19:56 ` luto at mit dot edu
@ 2015-07-05 20:36 ` hjl.tools at gmail dot com
  2015-07-05 20:49 ` luto at mit dot edu
                   ` (2 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: hjl.tools at gmail dot com @ 2015-07-05 20:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

--- Comment #20 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Andy Lutomirski from comment #19)
> I don't think the fix is correct.
> 
> This works:
> 
> gcc -mno-sse -mpreferred-stack-boundary=3 ...
> 
> This does not:
> 
> gcc -mno-sse -mpreferred-stack-boundary=3 -mincoming-stack-boundary=3 ...
>

Please provide a testcase.

> This makes no sense, since they should be equivalent.
> 
> Also, I find the docs to be unclear as to what different values of the
> incoming and preferred stack boundaries mean.
> 
> Finally, why is -mno-sse required in order to set a low stack boundary? 
> Couldn't gcc figure out that the existence of a stack variable (SSE,
> alignas, __attribute__((aligned(32))), etc) should force dynamic stack
> alignment? 

Since the x86-86 psABI says that stack must be 16 byte aligned, if the stack
isn't 16-byte aligned,  the code with SSE insn, which follows the psABI,
will crash when called with 8-byte aligned stack.


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (21 preceding siblings ...)
  2015-07-05 20:36 ` hjl.tools at gmail dot com
@ 2015-07-05 20:49 ` luto at mit dot edu
  2015-07-05 21:04 ` hjl.tools at gmail dot com
  2015-07-06 11:51 ` hjl at gcc dot gnu.org
  24 siblings, 0 replies; 27+ messages in thread
From: luto at mit dot edu @ 2015-07-05 20:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

--- Comment #21 from Andy Lutomirski <luto at mit dot edu> ---
(In reply to H.J. Lu from comment #20)
> (In reply to Andy Lutomirski from comment #19)
> > I don't think the fix is correct.
> > 
> > This works:
> > 
> > gcc -mno-sse -mpreferred-stack-boundary=3 ...
> > 
> > This does not:
> > 
> > gcc -mno-sse -mpreferred-stack-boundary=3 -mincoming-stack-boundary=3 ...
> >
> 
> Please provide a testcase.

No code needed:

$ touch foo.c
$ gcc -c -mno-sse -mpreferred-stack-boundary=3 -mincoming-stack-boundary=3
foo.c
foo.c:1:0: error: -mincoming-stack-boundary=3 is not between 4 and 12
$ gcc -c -mno-sse -mpreferred-stack-boundary=3 foo.c

> 
> > This makes no sense, since they should be equivalent.
> > 
> > Also, I find the docs to be unclear as to what different values of the
> > incoming and preferred stack boundaries mean.
> > 
> > Finally, why is -mno-sse required in order to set a low stack boundary? 
> > Couldn't gcc figure out that the existence of a stack variable (SSE,
> > alignas, __attribute__((aligned(32))), etc) should force dynamic stack
> > alignment? 
> 
> Since the x86-86 psABI says that stack must be 16 byte aligned, if the stack
> isn't 16-byte aligned,  the code with SSE insn, which follows the psABI,
> will crash when called with 8-byte aligned stack.

I'm confused here.  I agree in principle, but I don't actually think that gcc
works this way, or, if it does, it shouldn't.

If I compile with -mpreferred-stack-boundary=3 and create an aligned(32) local
variable, then gcc will dynamically align the stack and the variable will have
correct alignment even if the incoming stack was not 16-byte aligned.

Shouldn't an SSE variable work exactly the same way?  That is, if gcc is
generating an SSE instruction with a memory reference to an on-stack variable
that requires 16-byte alignment (movdqa, for example), wouldn't that variable
be effectively aligned(16) or greater and thus trigger dynamic stack alignment.

Sure, the generated SSE code will be less efficient with
-mpreferred-stack-boundary=3 (because neither "and $-16,%rsp" nor the required
frame pointer is free), but it should still work, right?


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (22 preceding siblings ...)
  2015-07-05 20:49 ` luto at mit dot edu
@ 2015-07-05 21:04 ` hjl.tools at gmail dot com
  2015-07-06 11:51 ` hjl at gcc dot gnu.org
  24 siblings, 0 replies; 27+ messages in thread
From: hjl.tools at gmail dot com @ 2015-07-05 21:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

--- Comment #22 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Andy Lutomirski from comment #21)

> $ touch foo.c
> $ gcc -c -mno-sse -mpreferred-stack-boundary=3 -mincoming-stack-boundary=3
> foo.c
> foo.c:1:0: error: -mincoming-stack-boundary=3 is not between 4 and 12
> $ gcc -c -mno-sse -mpreferred-stack-boundary=3 foo.c

I will fix it.

> > 
> > > This makes no sense, since they should be equivalent.
> > > 
> > > Also, I find the docs to be unclear as to what different values of the
> > > incoming and preferred stack boundaries mean.
> > > 
> > > Finally, why is -mno-sse required in order to set a low stack boundary? 
> > > Couldn't gcc figure out that the existence of a stack variable (SSE,
> > > alignas, __attribute__((aligned(32))), etc) should force dynamic stack
> > > alignment? 
> > 
> > Since the x86-86 psABI says that stack must be 16 byte aligned, if the stack
> > isn't 16-byte aligned,  the code with SSE insn, which follows the psABI,
> > will crash when called with 8-byte aligned stack.
> 
> I'm confused here.  I agree in principle, but I don't actually think that
> gcc works this way, or, if it does, it shouldn't.
> 
> If I compile with -mpreferred-stack-boundary=3 and create an aligned(32)
> local variable, then gcc will dynamically align the stack and the variable
> will have correct alignment even if the incoming stack was not 16-byte
> aligned.

That is correct.

> Sure, the generated SSE code will be less efficient with
> -mpreferred-stack-boundary=3 (because neither "and $-16,%rsp" nor the
> required frame pointer is free), but it should still work, right?

It works only if ALL codes are compiled with -mpreferred-stack-boundary=3.


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [Bug target/53383] Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
                   ` (23 preceding siblings ...)
  2015-07-05 21:04 ` hjl.tools at gmail dot com
@ 2015-07-06 11:51 ` hjl at gcc dot gnu.org
  24 siblings, 0 replies; 27+ messages in thread
From: hjl at gcc dot gnu.org @ 2015-07-06 11:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383

--- Comment #23 from hjl at gcc dot gnu.org <hjl at gcc dot gnu.org> ---
Author: hjl
Date: Mon Jul  6 11:50:47 2015
New Revision: 225452

URL: https://gcc.gnu.org/viewcvs?rev=225452&root=gcc&view=rev
Log:
Allow -mincoming-stack-boundary=3 with -mno-sse

Similar to -mpreferred-stack-boundary=3, -mincoming-stack-boundary=3 is
allowed with -mno-sse in 64-bit mode.

gcc/

        PR target/53383
        * config/i386/i386.c (ix86_option_override_internal): Allow
        -mincoming-stack-boundary=3 for 64-bit if SSE is disabled.

gcc/testsuite/

        PR target/53383
        * gcc.target/i386/pr53383-1.c: New file.
        * gcc.target/i386/pr53383-2.c: Likewise.
        * gcc.target/i386/pr53383-3.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr53383-1.c
    trunk/gcc/testsuite/gcc.target/i386/pr53383-2.c
    trunk/gcc/testsuite/gcc.target/i386/pr53383-3.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2015-07-06 11:51 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-17  0:19 [Bug c/53383] New: Allow -mpreferred-stack-boundary=3 on x86-64 hpa at zytor dot com
2012-05-17 14:12 ` [Bug target/53383] " hjl.tools at gmail dot com
2012-05-17 14:29 ` hpa at zytor dot com
2012-05-17 15:44 ` hjl.tools at gmail dot com
2012-05-17 16:00 ` hpa at zytor dot com
2012-05-17 16:28 ` hpa at zytor dot com
2012-05-18 11:41 ` rguenth at gcc dot gnu.org
2012-05-18 12:02 ` hubicka at gcc dot gnu.org
2012-05-18 17:29 ` hpa at zytor dot com
2012-05-19 19:22 ` hubicka at ucw dot cz
2012-05-19 21:28 ` hjl.tools at gmail dot com
2012-05-19 21:54 ` hubicka at ucw dot cz
2012-05-20  4:45 ` hjl.tools at gmail dot com
2012-05-20 11:15 ` hubicka at ucw dot cz
2012-05-20 11:35   ` Jan Hubicka
2012-05-20 13:56 ` hubicka at ucw dot cz
2012-05-20 15:36 ` hjl.tools at gmail dot com
2012-05-20 15:39 ` hjl.tools at gmail dot com
2012-06-22 17:11 ` hjl at gcc dot gnu.org
2012-06-22 17:12 ` hjl.tools at gmail dot com
2012-06-22 17:13 ` hjl at gcc dot gnu.org
2013-02-27 10:22 ` paolo.carlini at oracle dot com
2015-07-05 19:56 ` luto at mit dot edu
2015-07-05 20:36 ` hjl.tools at gmail dot com
2015-07-05 20:49 ` luto at mit dot edu
2015-07-05 21:04 ` hjl.tools at gmail dot com
2015-07-06 11:51 ` hjl at gcc dot gnu.org

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).