Message ID | 20220707103050.2849360-1-chenglulu@loongson.cn |
---|---|
State | New |
Headers | show |
Series | [v3] LoongArch: Modify fp_sp_offset and gp_sp_offset's calculation method when frame->mask or frame->fmask is zero. | expand |
On Thu, 2022-07-07 at 18:30 +0800, Lulu Cheng wrote: /* snip */ > diff --git a/gcc/testsuite/gcc.target/loongarch/prolog-opt.c > b/gcc/testsuite/gcc.target/loongarch/prolog-opt.c > new file mode 100644 > index 00000000000..c7bd71dde93 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/loongarch/prolog-opt.c > @@ -0,0 +1,15 @@ > +/* Test that LoongArch backend stack drop operation optimized. */ > + > +/* { dg-do compile } */ > +/* { dg-options "-O2 -mabi=lp64d" } */ > +/* { dg-final { scan-assembler "addi.d\t\\\$r3,\\\$r3,-16" } } */ > + > +#include <stdio.h> It's better to hard code "extern int printf(char *, ...);" here, so the test case won't unnecessarily depend on libc header. LGTM otherwise. > + > +int main() > +{ > + char buf[1024 * 12]; > + printf ("%p\n", buf); > + return 0; > +} > +
在 2022/7/7 下午7:51, Xi Ruoyao 写道: > On Thu, 2022-07-07 at 18:30 +0800, Lulu Cheng wrote: > > /* snip */ > > >> diff --git a/gcc/testsuite/gcc.target/loongarch/prolog-opt.c >> b/gcc/testsuite/gcc.target/loongarch/prolog-opt.c >> new file mode 100644 >> index 00000000000..c7bd71dde93 >> --- /dev/null >> +++ b/gcc/testsuite/gcc.target/loongarch/prolog-opt.c >> @@ -0,0 +1,15 @@ >> +/* Test that LoongArch backend stack drop operation optimized. */ >> + >> +/* { dg-do compile } */ >> +/* { dg-options "-O2 -mabi=lp64d" } */ >> +/* { dg-final { scan-assembler "addi.d\t\\\$r3,\\\$r3,-16" } } */ >> + >> +#include <stdio.h> > It's better to hard code "extern int printf(char *, ...);" here, so the > test case won't unnecessarily depend on libc header. > > LGTM otherwise. > OK! Thanks!:-)
diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index d72b256df51..5c9a33c14f7 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -917,8 +917,12 @@ loongarch_compute_frame_info (void) frame->frame_pointer_offset = offset; /* Next are the callee-saved FPRs. */ if (frame->fmask) - offset += LARCH_STACK_ALIGN (num_f_saved * UNITS_PER_FP_REG); - frame->fp_sp_offset = offset - UNITS_PER_FP_REG; + { + offset += LARCH_STACK_ALIGN (num_f_saved * UNITS_PER_FP_REG); + frame->fp_sp_offset = offset - UNITS_PER_FP_REG; + } + else + frame->fp_sp_offset = offset; /* Next are the callee-saved GPRs. */ if (frame->mask) { @@ -931,8 +935,10 @@ loongarch_compute_frame_info (void) frame->save_libcall_adjustment = x_save_size; offset += x_save_size; + frame->gp_sp_offset = offset - UNITS_PER_WORD; } - frame->gp_sp_offset = offset - UNITS_PER_WORD; + else + frame->gp_sp_offset = offset; /* The hard frame pointer points above the callee-saved GPRs. */ frame->hard_frame_pointer_offset = offset; /* Above the hard frame pointer is the callee-allocated varags save area. */ diff --git a/gcc/testsuite/gcc.target/loongarch/prolog-opt.c b/gcc/testsuite/gcc.target/loongarch/prolog-opt.c new file mode 100644 index 00000000000..c7bd71dde93 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/prolog-opt.c @@ -0,0 +1,15 @@ +/* Test that LoongArch backend stack drop operation optimized. */ + +/* { dg-do compile } */ +/* { dg-options "-O2 -mabi=lp64d" } */ +/* { dg-final { scan-assembler "addi.d\t\\\$r3,\\\$r3,-16" } } */ + +#include <stdio.h> + +int main() +{ + char buf[1024 * 12]; + printf ("%p\n", buf); + return 0; +} +