Skip to content

Commit 853eb57

Browse files
hjl-toolsH.J. Lu
authored and
H.J. Lu
committed
x86-64: Generate push2/pop2 only if the incoming stack is 16-byte aligned
Since push2/pop2 requires 16-byte stack alignment, don't generate them if the incoming stack isn't 16-byte aligned. gcc/ PR target/113912 * config/i386/i386.cc (ix86_can_use_push2pop2): New. (ix86_pro_and_epilogue_can_use_push2pop2): Use it. (ix86_emit_save_regs): Don't generate push2 if ix86_can_use_push2pop2 return false. (ix86_expand_epilogue): Don't generate pop2 if ix86_can_use_push2pop2 return false. gcc/testsuite/ PR target/113912 * gcc.target/i386/apx-push2pop2-2.c: New test.
1 parent e63ae90 commit 853eb57

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

gcc/config/i386/i386.cc

+18-6
Original file line numberDiff line numberDiff line change
@@ -6802,16 +6802,24 @@ get_probe_interval (void)
68026802

68036803
#define SPLIT_STACK_AVAILABLE 256
68046804

6805-
/* Helper function to determine whether push2/pop2 can be used in prologue or
6806-
epilogue for register save/restore. */
6805+
/* Return true if push2/pop2 can be generated. */
6806+
68076807
static bool
6808-
ix86_pro_and_epilogue_can_use_push2pop2 (int nregs)
6808+
ix86_can_use_push2pop2 (void)
68096809
{
68106810
/* Use push2/pop2 only if the incoming stack is 16-byte aligned. */
68116811
unsigned int incoming_stack_boundary
68126812
= (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
68136813
? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
6814-
if (incoming_stack_boundary % 128 != 0)
6814+
return incoming_stack_boundary % 128 == 0;
6815+
}
6816+
6817+
/* Helper function to determine whether push2/pop2 can be used in prologue or
6818+
epilogue for register save/restore. */
6819+
static bool
6820+
ix86_pro_and_epilogue_can_use_push2pop2 (int nregs)
6821+
{
6822+
if (!ix86_can_use_push2pop2 ())
68156823
return false;
68166824
int aligned = cfun->machine->fs.sp_offset % 16 == 0;
68176825
return TARGET_APX_PUSH2POP2
@@ -7401,7 +7409,9 @@ ix86_emit_save_regs (void)
74017409
int regno;
74027410
rtx_insn *insn;
74037411

7404-
if (!TARGET_APX_PUSH2POP2 || cfun->machine->func_type != TYPE_NORMAL)
7412+
if (!TARGET_APX_PUSH2POP2
7413+
|| !ix86_can_use_push2pop2 ()
7414+
|| cfun->machine->func_type != TYPE_NORMAL)
74057415
{
74067416
for (regno = FIRST_PSEUDO_REGISTER - 1; regno >= 0; regno--)
74077417
if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
@@ -10039,7 +10049,9 @@ ix86_expand_epilogue (int style)
1003910049
m->fs.cfa_reg == stack_pointer_rtx);
1004010050
}
1004110051

10042-
if (TARGET_APX_PUSH2POP2 && m->func_type == TYPE_NORMAL)
10052+
if (TARGET_APX_PUSH2POP2
10053+
&& ix86_can_use_push2pop2 ()
10054+
&& m->func_type == TYPE_NORMAL)
1004310055
ix86_emit_restore_regs_using_pop2 ();
1004410056
else
1004510057
ix86_emit_restore_regs_using_pop (TARGET_APX_PPX);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* { dg-do compile { target { ! ia32 } } } */
2+
/* { dg-options "-O2 -mpreferred-stack-boundary=3 -mapx-features=push2pop2 -fomit-frame-pointer" } */
3+
4+
extern int bar (int);
5+
6+
void foo ()
7+
{
8+
int a,b,c,d,e,f,i;
9+
a = bar (5);
10+
b = bar (a);
11+
c = bar (b);
12+
d = bar (c);
13+
e = bar (d);
14+
f = bar (e);
15+
for (i = 1; i < 10; i++)
16+
{
17+
a += bar (a + i) + bar (b + i) +
18+
bar (c + i) + bar (d + i) +
19+
bar (e + i) + bar (f + i);
20+
}
21+
}
22+
23+
/* { dg-final { scan-assembler-not "push2(|p)\[\\t \]*%r" } } */
24+
/* { dg-final { scan-assembler-not "pop2(|p)\[\\t \]*%r" } } */

0 commit comments

Comments
 (0)