[Bug target/81736] New: Unnecessary save and restore frame pointer with -fno-omit-frame-pointer

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Bug target/81736] New: Unnecessary save and restore frame pointer with -fno-omit-frame-pointer

daniel.kruegler at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81736

            Bug ID: 81736
           Summary: Unnecessary save and restore frame pointer with
                    -fno-omit-frame-pointer
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hjl.tools at gmail dot com
                CC: ubizjak at gmail dot com
  Target Milestone: ---
            Target: x86-64

[hjl@gnu-4 tmp]$ cat y.i
extern int i;

int foo (void)
{
return i;
}

[hjl@gnu-4 tmp]$ gcc -S -O3 y.i -fno-omit-frame-pointer                
[hjl@gnu-4 tmp]$ cat y.s
        .file   "y.i"
        .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    i(%rip), %eax
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
        popq    %rbp
        .cfi_def_cfa 7, 8
        ret
        .cfi_endproc
.LFE0:
        .size   foo, .-foo

There is no need to save and restore frame pointer since stack is untouched.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Bug target/81736] Unnecessary save and restore frame pointer with -fno-omit-frame-pointer

daniel.kruegler at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81736

--- Comment #1 from hjl at gcc dot gnu.org <hjl at gcc dot gnu.org> ---
Author: hjl
Date: Mon Aug  7 11:49:10 2017
New Revision: 250916

URL: https://gcc.gnu.org/viewcvs?rev=250916&root=gcc&view=rev
Log:
i386: Don't use frame pointer without stack access

When there is no stack access, there is no need to use frame pointer
even if -fno-omit-frame-pointer is used.

gcc/

        PR target/81736
        * config/i386/i386.c (ix86_finalize_stack_realign_flags): Renamed
        to ...
        (ix86_finalize_stack_frame_flags): This.  Also clear
        frame_pointer_needed if -fno-omit-frame-pointer is used without
        stack access.
        (ix86_expand_prologue): Replace ix86_finalize_stack_realign_flags
        with ix86_finalize_stack_frame_flags.
        (ix86_expand_epilogue): Likewise.
        (ix86_expand_split_stack_prologue): Likewise.

gcc/testsuite/

        PR target/81736
        * gcc.target/i386/pr81736-1.c: New test.
        * gcc.target/i386/pr81736-2.c: Likewise.
        * gcc.target/i386/pr81736-3.c: Likewise.
        * gcc.target/i386/pr81736-4.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr81736-1.c
    trunk/gcc/testsuite/gcc.target/i386/pr81736-2.c
    trunk/gcc/testsuite/gcc.target/i386/pr81736-3.c
    trunk/gcc/testsuite/gcc.target/i386/pr81736-4.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c
    trunk/gcc/testsuite/ChangeLog
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Bug target/81736] Unnecessary save and restore frame pointer with -fno-omit-frame-pointer

daniel.kruegler at googlemail dot com
In reply to this post by daniel.kruegler at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81736

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |8.0

--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
Fixed.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Bug target/81736] Unnecessary save and restore frame pointer with -fno-omit-frame-pointer

daniel.kruegler at googlemail dot com
In reply to this post by daniel.kruegler at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81736

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
   Last reconfirmed|                            |2017-08-08
         Resolution|FIXED                       |---
     Ever confirmed|0                           |1

--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> ---
The patch was reverted.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Bug target/81736] Unnecessary save and restore frame pointer with -fno-omit-frame-pointer

daniel.kruegler at googlemail dot com
In reply to this post by daniel.kruegler at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81736

--- Comment #4 from H.J. Lu <hjl.tools at gmail dot com> ---
Another weird code with -fno-omit-frame-pointer:

[hjl@gnu-6 pr59501]$ cat k.i
typedef int v8si __attribute__ ((vector_size (32)));

void
foo (v8si *idx, v8si *out_start, v8si *out_end,
     v8si *regions)
{
    v8si base = regions[3];
    *out_start = base;
    *out_end = base;
}
[hjl@gnu-6 pr59501]$ make k.s
/export/build/gnu/gcc/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -O -fno-omit-frame-pointer
-mavx -S k.i
[hjl@gnu-6 pr59501]$ cat k.s
        .file   "k.i"
        .text
        .globl  foo
        .type   foo, @function
foo:
.LFB0:
        .cfi_startproc
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
        andq    $-32, %rsp  <<<<<<<<<<<< Why do we realign stack?
        vmovdqa 96(%rcx), %ymm0
        vmovdqa %ymm0, (%rsi)
        vmovdqa %ymm0, (%rdx)
        leave
        .cfi_def_cfa 7, 8
        ret
        .cfi_endproc
.LFE0:
        .size   foo, .-foo
        .ident  "GCC: (GNU) 8.0.0 20170807 (experimental)"
        .section        .note.GNU-stack,"",@progbits
[hjl@gnu-6 pr59501]$
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Bug target/81736] Unnecessary save and restore frame pointer with -fno-omit-frame-pointer

daniel.kruegler at googlemail dot com
In reply to this post by daniel.kruegler at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81736

--- Comment #5 from hjl at gcc dot gnu.org <hjl at gcc dot gnu.org> ---
Author: hjl
Date: Thu Aug 10 15:29:05 2017
New Revision: 251028

URL: https://gcc.gnu.org/viewcvs?rev=251028&root=gcc&view=rev
Log:
i386: Don't use frame pointer without stack access

When there is no stack access, there is no need to use frame pointer
even if -fno-omit-frame-pointer is used and caller's frame pointer is
unchanged.

gcc/

        PR target/81736
        * config/i386/i386.c (ix86_finalize_stack_realign_flags): Renamed
        to ...
        (ix86_finalize_stack_frame_flags): This.  Also clear
        frame_pointer_needed if -fno-omit-frame-pointer is used without
        stack access.
        (ix86_expand_prologue): Replace ix86_finalize_stack_realign_flags
        with ix86_finalize_stack_frame_flags.
        (ix86_expand_epilogue): Likewise.
        (ix86_expand_split_stack_prologue): Likewise.
        * doc/invoke.texi: Add a note for -fno-omit-frame-pointer.

gcc/testsuite/

        PR target/81736
        * gcc.target/i386/pr81736-1.c: New test.
        * gcc.target/i386/pr81736-2.c: Likewise.
        * gcc.target/i386/pr81736-3.c: Likewise.
        * gcc.target/i386/pr81736-4.c: Likewise.
        * gcc.target/i386/pr81736-5.c: Likewise.
        * gcc.target/i386/pr81736-6.c: Likewise.
        * gcc.target/i386/pr81736-7.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr81736-1.c
    trunk/gcc/testsuite/gcc.target/i386/pr81736-2.c
    trunk/gcc/testsuite/gcc.target/i386/pr81736-3.c
    trunk/gcc/testsuite/gcc.target/i386/pr81736-4.c
    trunk/gcc/testsuite/gcc.target/i386/pr81736-5.c
    trunk/gcc/testsuite/gcc.target/i386/pr81736-6.c
    trunk/gcc/testsuite/gcc.target/i386/pr81736-7.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c
    trunk/gcc/doc/invoke.texi
    trunk/gcc/testsuite/ChangeLog
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Bug target/81736] Unnecessary save and restore frame pointer with -fno-omit-frame-pointer

daniel.kruegler at googlemail dot com
In reply to this post by daniel.kruegler at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81736

Rainer Orth <ro at gcc dot gnu.org> changed:

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

--- Comment #6 from Rainer Orth <ro at gcc dot gnu.org> ---
Two of the new tests FAIL on 32-bit Solaris/x86:

+FAIL: gcc.target/i386/pr81736-3.c scan-assembler %[re]bp
+FAIL: gcc.target/i386/pr81736-4.c scan-assembler %[re]bp

The body of the first one (when configured with gas) is just

foo:
        pushl   %ebx
/APP
/ 7 "/vol/gcc/src/hg/trunk/local/gcc/testsuite/gcc.target/i386/pr81736-3.c" 1
        #
/ 0 "" 2
/NO_APP
        popl    %ebx
        ret

  Rainer
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Bug target/81736] Unnecessary save and restore frame pointer with -fno-omit-frame-pointer

daniel.kruegler at googlemail dot com
In reply to this post by daniel.kruegler at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81736

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Rainer Orth from comment #6)

> Two of the new tests FAIL on 32-bit Solaris/x86:
>
> +FAIL: gcc.target/i386/pr81736-3.c scan-assembler %[re]bp
> +FAIL: gcc.target/i386/pr81736-4.c scan-assembler %[re]bp
>
> The body of the first one (when configured with gas) is just
>
> foo:
>         pushl   %ebx
> /APP
> / 7 "/vol/gcc/src/hg/trunk/local/gcc/testsuite/gcc.target/i386/pr81736-3.c" 1
>         #
> / 0 "" 2
> /NO_APP
>         popl    %ebx
>         ret
>
>   Rainer

I backed out my change and got

[hjl@gnu-tools-1 gcc]$
/export/build/gnu/gcc-cross/build-i386-solaris2.11/gcc/xgcc
-B/export/build/gnu/gcc-cross/build-i386-solaris2.11/gcc/
/export/gnu/import/git/sources/gcc/gcc/testsuite/gcc.target/i386/pr81736-3.c
-fno-diagnostics-show-caret -fdiagnostics-color=never -mclear-hwcap -O2
-fno-omit-frame-pointer -S -o pr81736-3.s
[hjl@gnu-tools-1 gcc]$ cat pr81736-3.s
        .file   "pr81736-3.c"
        .text
        .align 16
        .globl  foo
        .type   foo, @function
foo:
        pushl   %ebx
/APP
/ 7
"/export/gnu/import/git/sources/gcc/gcc/testsuite/gcc.target/i386/pr81736-3.c"
1
        #
/NO_APP
        popl    %ebx
        ret
        .size   foo, .-foo
        .ident  "GCC: (GNU) 8.0.0 20170812 (experimental)"
[hjl@gnu-tools-1 gcc]$

These 2 testcases may have exposed an existing issue for Solaris/i386 target.
Please verify it with GCC 7 and open a new bug if this is a real issue.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Bug target/81736] Unnecessary save and restore frame pointer with -fno-omit-frame-pointer

daniel.kruegler at googlemail dot com
In reply to this post by daniel.kruegler at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81736

--- Comment #8 from H.J. Lu <hjl.tools at gmail dot com> ---
i386/sol2.h has

#define SUBTARGET_OPTIMIZATION_OPTIONS                          \
  { OPT_LEVELS_1_PLUS, OPT_momit_leaf_frame_pointer, NULL, 1 }

i386.c:

 /* Keep nonleaf frame pointers.  */
  if (opts->x_flag_omit_frame_pointer)
    opts->x_target_flags &= ~MASK_OMIT_LEAF_FRAME_POINTER;
  else if (TARGET_OMIT_LEAF_FRAME_POINTER_P (opts->x_target_flags))
    opts->x_flag_omit_frame_pointer = 1;

flag_omit_frame_pointer is always true and -fno-omit-frame-pointer
is ignored for Solaris.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Bug target/81736] Unnecessary save and restore frame pointer with -fno-omit-frame-pointer

daniel.kruegler at googlemail dot com
In reply to this post by daniel.kruegler at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81736

--- Comment #9 from H.J. Lu <hjl.tools at gmail dot com> ---
Add -mno-omit-leaf-frame-pointer should make these tests pass on Solaris.
Loading...