Uros,
This patch enables the fuse-caller-save optimization for i386.
It sets the hook TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS to true.
The definition of the hook is:
...
set to true if all the calls in the current function contain clobbers in
CALL_INSN_FUNCTION_USAGE for the registers that are clobbered by the call rather
than by the callee, and are not already set or clobbered in the call pattern.
Examples of such registers are registers used in PLTs and stubs, and temporary
registers used in the call instruction but not present in the rtl pattern.
Another way to formulate it is the registers not present in the rtl pattern that
are clobbered by the call assuming the callee does not clobber any register. The
default version of this hook is set to false.
...
Bootstrapped and reg-tested this patch on x86_64, no issues found.
Is it in fact safe to set this hook to true for i386? Are there clobbers which
need to be added?
If it's safe to set this hook to true, OK for trunk?
Thanks,
- Tom
2014-05-30 Tom de Vries <t...@codesourcery.com>
* config/i386/i386.c (TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS):
Redefine as true.
* gcc.target/i386/fuse-caller-save.c: New test.
* gcc.dg/ira-shrinkwrap-prep-1.c: Run with -fno-use-caller-save.
* gcc.dg/ira-shrinkwrap-prep-2.c: Same.
---
gcc/config/i386/i386.c | 3 +++
gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-1.c | 2 +-
gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-2.c | 2 +-
gcc/testsuite/gcc.target/i386/fuse-caller-save.c | 25 ++++++++++++++++++++++++
4 files changed, 30 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/i386/fuse-caller-save.c
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 8827256..83d3ba3 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -47272,6 +47272,9 @@ ix86_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update)
#undef TARGET_MODE_PRIORITY
#define TARGET_MODE_PRIORITY ix86_mode_priority
+#undef TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS
+#define TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS true
+
struct gcc_target targetm = TARGET_INITIALIZER;
#include "gt-i386.h"
diff --git a/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-1.c b/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-1.c
index 171a2bd..fc7b142 100644
--- a/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-1.c
+++ b/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-1.c
@@ -1,5 +1,5 @@
/* { dg-do compile { target { { x86_64-*-* && lp64 } || { powerpc*-*-* && lp64 } } } } */
-/* { dg-options "-O3 -fdump-rtl-ira -fdump-rtl-pro_and_epilogue" } */
+/* { dg-options "-O3 -fdump-rtl-ira -fdump-rtl-pro_and_epilogue -fno-use-caller-save" } */
long __attribute__((noinline, noclone))
foo (long a)
diff --git a/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-2.c b/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-2.c
index ed08494..2e5a9cf 100644
--- a/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-2.c
+++ b/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-2.c
@@ -1,5 +1,5 @@
/* { dg-do compile { target { { x86_64-*-* && lp64 } || { powerpc*-*-* && lp64 } } } } */
-/* { dg-options "-O3 -fdump-rtl-ira -fdump-rtl-pro_and_epilogue" } */
+/* { dg-options "-O3 -fdump-rtl-ira -fdump-rtl-pro_and_epilogue -fno-use-caller-save" } */
long __attribute__((noinline, noclone))
foo (long a)
diff --git a/gcc/testsuite/gcc.target/i386/fuse-caller-save.c b/gcc/testsuite/gcc.target/i386/fuse-caller-save.c
new file mode 100644
index 0000000..ff77d81
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/fuse-caller-save.c
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fuse-caller-save" } */
+/* Testing -fuse-caller-save optimization option. */
+
+static int __attribute__((noinline))
+bar (int x)
+{
+ return x + 3;
+}
+
+int __attribute__((noinline))
+foo (int y)
+{
+ return y + bar (y);
+}
+
+int
+main (void)
+{
+ return !(foo (5) == 13);
+}
+
+/* { dg-final { scan-assembler-not "\.cfi_def_cfa_offset" } } */
+/* { dg-final { scan-assembler-not "\.cfi_offset" } } */
+
--
1.9.1