2015-03-24 Anton Blanchard PR target/63354 * config/rs6000/rs6000.h (TARGET_KEEP_LEAF_WHEN_PROFILED): Define. * config/rs6000/rs6000.c (rs6000_keep_leaf_when_profiled): New function. 2015-03-24 Martin Sebor PR target/63354 * gcc.target/powerpc/pr63354.c: New test. diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 31b46ea..f1508b9 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -24397,6 +24397,23 @@ rs6000_output_function_prologue (FILE *file, rs6000_pic_labelno++; } +/* -mprofile-kernel code calls mcount before the function prologue, + so a profiled leaf function should stay a leaf function. */ + +static bool +rs6000_keep_leaf_when_profiled (void) +{ + switch (DEFAULT_ABI) + { + case ABI_AIX: + case ABI_ELFv2: + return TARGET_PROFILE_KERNEL; + + default: + return true; + } +} + /* Non-zero if vmx regs are restored before the frame pop, zero if we restore after the pop when possible. */ #define ALWAYS_RESTORE_ALTIVEC_BEFORE_POP 0 diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h index ef6bb2f..50394b0 100644 --- a/gcc/config/rs6000/rs6000.h +++ b/gcc/config/rs6000/rs6000.h @@ -703,6 +703,9 @@ extern unsigned char rs6000_recip_bits[]; #define TARGET_CPU_CPP_BUILTINS() \ rs6000_cpu_cpp_builtins (pfile) +#undef TARGET_KEEP_LEAF_WHEN_PROFILED +#define TARGET_KEEP_LEAF_WHEN_PROFILED rs6000_keep_leaf_when_profiled + /* This is used by rs6000_cpu_cpp_builtins to indicate the byte order we're compiling for. Some configurations may need to override it. */ #define RS6000_CPU_CPP_ENDIAN_BUILTINS() \ diff --git a/gcc/testsuite/gcc.target/powerpc/pr63354.c b/gcc/testsuite/gcc.target/powerpc/pr63354.c new file mode 100644 index 0000000..9e635cc --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr63354.c @@ -0,0 +1,10 @@ +/* { dg-do compile { target { powerpc64*-*-linux* } } } */ +/* { dg-options "-O2 -pg -mprofile-kernel" } */ + +int foo (void) +{ + return 1; +} + +/* { dg-final { scan-assembler "bl _mcount" } } */ +/* { dg-final { scan-assembler-not "(addi|stdu) 1," } } */