Thank you for the quick reply. > Please repost after updating to test HAVE_prologue and HAVE_epilogue and > adding a testcase.
I have managed to reproduce the problem on the small test case on mips32, but the test is architecture independent and should probably fail on many other ports without this patch. The optimization is also disabled if macros HAVE_prologue and HAVE_epilogue are not defined or have false value. Radovan Patch - diff --git a/gcc/testsuite/gcc.dg/aru-2.c b/gcc/testsuite/gcc.dg/aru-2.c new file mode 100644 index 0000000..624bd7f --- /dev/null +++ b/gcc/testsuite/gcc.dg/aru-2.c @@ -0,0 +1,27 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -pg" } */ + +static int __attribute__((noinline)) +bar (int x) +{ + return x + 3; +} + +int __attribute__((noinline)) +foo (int y0, int y1, int y2, int y3, int y4) +{ + int r = 0; + r += bar (r + y4); + r += bar (r + y3); + r += bar (r + y2); + r += bar (r + y1); + r += bar (r + y0); + return r; +} + +int +main (void) +{ + int z = foo (0, 1, 2, 3, 4); + return !(z == 191); +} diff --git a/gcc/toplev.c b/gcc/toplev.c index eb37bfe..ddaf8e0 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -111,6 +111,13 @@ along with GCC; see the file COPYING3. If not see declarations for e.g. AIX 4.x. */ #endif +#ifndef HAVE_epilogue +#define HAVE_epilogue 0 +#endif +#ifndef HAVE_prologue +#define HAVE_prologue 0 +#endif + #include <new> static void general_init (const char *); @@ -1605,6 +1612,11 @@ process_options (void) /* Save the current optimization options. */ optimization_default_node = build_optimization_node (&global_options); optimization_current_node = optimization_default_node; + + /* Disable use caller save optimization if profiler is active or port + does not emit prologue and epilogue as RTL. */ + if (profile_flag || !HAVE_prologue || !HAVE_epilogue) + flag_use_caller_save = 0; } /* This function can be called multiple times to reinitialize the compiler