Skip to content

Commit cd557ff

Browse files
author
hjl
committed
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@251028 138bc75d-0d04-0410-961f-82ee72b054a4
1 parent 9d34721 commit cd557ff

File tree

11 files changed

+139
-11
lines changed

11 files changed

+139
-11
lines changed

gcc/ChangeLog

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
2017-08-10 H.J. Lu <[email protected]>
2+
3+
PR target/81736
4+
* config/i386/i386.c (ix86_finalize_stack_realign_flags): Renamed
5+
to ...
6+
(ix86_finalize_stack_frame_flags): This. Also clear
7+
frame_pointer_needed if -fno-omit-frame-pointer is used without
8+
stack access.
9+
(ix86_expand_prologue): Replace ix86_finalize_stack_realign_flags
10+
with ix86_finalize_stack_frame_flags.
11+
(ix86_expand_epilogue): Likewise.
12+
(ix86_expand_split_stack_prologue): Likewise.
13+
* doc/invoke.texi: Add a note for -fno-omit-frame-pointer.
14+
115
2017-08-10 Martin Liska <[email protected]>
216

317
PR c++/81355

gcc/config/i386/i386.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14179,10 +14179,11 @@ output_probe_stack_range (rtx reg, rtx end)
1417914179
return "";
1418014180
}
1418114181

14182-
/* Finalize stack_realign_needed flag, which will guide prologue/epilogue
14183-
to be generated in correct form. */
14182+
/* Finalize stack_realign_needed and frame_pointer_needed flags, which
14183+
will guide prologue/epilogue to be generated in correct form. */
14184+
1418414185
static void
14185-
ix86_finalize_stack_realign_flags (void)
14186+
ix86_finalize_stack_frame_flags (void)
1418614187
{
1418714188
/* Check if stack realign is really needed after reload, and
1418814189
stores result in cfun */
@@ -14205,13 +14206,13 @@ ix86_finalize_stack_realign_flags (void)
1420514206
}
1420614207

1420714208
/* If the only reason for frame_pointer_needed is that we conservatively
14208-
assumed stack realignment might be needed, but in the end nothing that
14209-
needed the stack alignment had been spilled, clear frame_pointer_needed
14210-
and say we don't need stack realignment. */
14211-
if (stack_realign
14209+
assumed stack realignment might be needed or -fno-omit-frame-pointer
14210+
is used, but in the end nothing that needed the stack alignment had
14211+
been spilled nor stack access, clear frame_pointer_needed and say we
14212+
don't need stack realignment. */
14213+
if ((stack_realign || !flag_omit_frame_pointer)
1421214214
&& frame_pointer_needed
1421314215
&& crtl->is_leaf
14214-
&& flag_omit_frame_pointer
1421514216
&& crtl->sp_is_unchanging
1421614217
&& !ix86_current_function_calls_tls_descriptor
1421714218
&& !crtl->accesses_prior_frames
@@ -14402,7 +14403,7 @@ ix86_expand_prologue (void)
1440214403
if (ix86_function_naked (current_function_decl))
1440314404
return;
1440414405

14405-
ix86_finalize_stack_realign_flags ();
14406+
ix86_finalize_stack_frame_flags ();
1440614407

1440714408
/* DRAP should not coexist with stack_realign_fp */
1440814409
gcc_assert (!(crtl->drap_reg && stack_realign_fp));
@@ -15266,7 +15267,7 @@ ix86_expand_epilogue (int style)
1526615267
return;
1526715268
}
1526815269

15269-
ix86_finalize_stack_realign_flags ();
15270+
ix86_finalize_stack_frame_flags ();
1527015271
frame = m->frame;
1527115272

1527215273
m->fs.sp_realigned = stack_realign_fp;
@@ -15801,7 +15802,7 @@ ix86_expand_split_stack_prologue (void)
1580115802

1580215803
gcc_assert (flag_split_stack && reload_completed);
1580315804

15804-
ix86_finalize_stack_realign_flags ();
15805+
ix86_finalize_stack_frame_flags ();
1580515806
frame = cfun->machine->frame;
1580615807
allocate = frame.stack_pointer_offset - INCOMING_FRAME_SP_OFFSET;
1580715808

gcc/doc/invoke.texi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7366,6 +7366,10 @@ size) for 32-bit GNU/Linux x86 and 32-bit Darwin x86 targets is
73667366
@option{-fomit-frame-pointer}. You can configure GCC with the
73677367
@option{--enable-frame-pointer} configure option to change the default.
73687368

7369+
Note that @option{-fno-omit-frame-pointer} doesn't force a new stack
7370+
frame for all functions if it isn't otherwise needed, and hence doesn't
7371+
guarantee a new frame pointer for all functions.
7372+
73697373
Enabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}.
73707374

73717375
@item -foptimize-sibling-calls

gcc/testsuite/ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2017-08-10 H.J. Lu <[email protected]>
2+
3+
PR target/81736
4+
* gcc.target/i386/pr81736-1.c: New test.
5+
* gcc.target/i386/pr81736-2.c: Likewise.
6+
* gcc.target/i386/pr81736-3.c: Likewise.
7+
* gcc.target/i386/pr81736-4.c: Likewise.
8+
* gcc.target/i386/pr81736-5.c: Likewise.
9+
* gcc.target/i386/pr81736-6.c: Likewise.
10+
* gcc.target/i386/pr81736-7.c: Likewise.
11+
112
2017-08-10 Will Schmidt <[email protected]>
213

314
* gcc.target/powerpc/fold-vec-msum-short.c: Fix typo.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-O2 -fno-omit-frame-pointer" } */
3+
4+
extern int i;
5+
6+
int
7+
foo (void)
8+
{
9+
return i;
10+
}
11+
12+
/* No need to use a frame pointer. */
13+
/* { dg-final { scan-assembler-not "%\[re\]bp" } } */
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-O2 -fno-omit-frame-pointer" } */
3+
4+
int
5+
#ifndef __x86_64__
6+
__attribute__((regparm(3)))
7+
#endif
8+
foo (int i)
9+
{
10+
return i;
11+
}
12+
13+
/* No need to use a frame pointer. */
14+
/* { dg-final { scan-assembler-not "%\[re\]bp" } } */
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-O2 -fno-omit-frame-pointer" } */
3+
4+
void
5+
foo (void)
6+
{
7+
asm ("# " : : : "ebx");
8+
}
9+
10+
/* Need to use a frame pointer. */
11+
/* { dg-final { scan-assembler "%\[re\]bp" } } */
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-O2 -fno-omit-frame-pointer" } */
3+
4+
int
5+
foo (int i1, int i2, int i3, int i4, int i5, int i6, int i7)
6+
{
7+
return i7;
8+
}
9+
10+
/* Need to use a frame pointer. */
11+
/* { dg-final { scan-assembler "%\[re\]bp" } } */
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-O2 -fno-omit-frame-pointer -mavx" } */
3+
4+
typedef int v8si __attribute__ ((vector_size (32)));
5+
6+
void
7+
#ifndef __x86_64__
8+
__attribute__((regparm(3)))
9+
#endif
10+
foo (v8si *out_start, v8si *out_end, v8si *regions)
11+
{
12+
v8si base = regions[3];
13+
*out_start = base;
14+
*out_end = base;
15+
}
16+
17+
/* No need to use a frame pointer. */
18+
/* { dg-final { scan-assembler-not "%\[re\]bp" } } */
19+
/* Verify no dynamic realignment is performed. */
20+
/* { dg-final { scan-assembler-not "and\[^\n\r]*sp" } } */
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-O2 -fno-omit-frame-pointer" } */
3+
4+
struct foo
5+
{
6+
int head;
7+
} a;
8+
9+
int
10+
bar (void)
11+
{
12+
return a.head != 0;
13+
}
14+
15+
/* No need to use a frame pointer. */
16+
/* { dg-final { scan-assembler-not "%\[re\]bp" } } */

0 commit comments

Comments
 (0)