This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Don't optimize local functions calling conventions at -O0 (PR target/39496)


Hi!

We shouldn't be optimizing function call calling conventions at -O0, as that
makes it impossible to call those functions from inferior (DW_AT_location of
DW_TAG_formal_parameter DIEs at least at -O0 describes just where is the
argument stored after entering the prologue, not where it is actually passed).

Bootstrapped/regtested on x86_64-linux and i686-linux.  Ok for trunk?

2009-03-19  Jakub Jelinek  <jakub@redhat.com>

	PR target/39496
	* config/i386/i386.c (ix86_function_regparm): Don't optimize local
	functions using regparm calling conventions when not optimizing.
	(ix86_function_sseregparm): Similarly for sseregparm calling
	conventions.

	* gcc.target/i386/pr39496.c: New test.
	* g++.dg/other/pr39496.C: New test.

--- gcc/config/i386/i386.c.jj	2009-03-16 21:30:40.000000000 +0100
+++ gcc/config/i386/i386.c	2009-03-19 08:31:52.000000000 +0100
@@ -4311,7 +4311,9 @@ ix86_function_regparm (const_tree type, 
     return 2;
 
   /* Use register calling convention for local functions when possible.  */
-  if (decl && TREE_CODE (decl) == FUNCTION_DECL
+  if (decl
+      && TREE_CODE (decl) == FUNCTION_DECL
+      && optimize
       && !profile_flag)
     {
       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
@@ -4396,7 +4398,7 @@ ix86_function_sseregparm (const_tree typ
 
   /* For local functions, pass up to SSE_REGPARM_MAX SFmode
      (and DFmode for SSE2) arguments in SSE registers.  */
-  if (decl && TARGET_SSE_MATH && !profile_flag)
+  if (decl && TARGET_SSE_MATH && optimize && !profile_flag)
     {
       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
--- gcc/testsuite/gcc.target/i386/pr39496.c.jj	2009-03-19 08:40:56.000000000 +0100
+++ gcc/testsuite/gcc.target/i386/pr39496.c	2009-03-19 08:49:41.000000000 +0100
@@ -0,0 +1,35 @@
+/* PR target/39496 */
+/* { dg-do compile { target { { i?86-*-linux* x86_64-*-linux* } && ilp32 } } } */
+/* { dg-options "-O0 -fverbose-asm -fno-omit-frame-pointer -msse2 -mfpmath=sse" } */
+/* Verify that {foo,bar}{,2}param are all passed on the stack, using
+   normal calling conventions, when not optimizing.  */
+/* { dg-final { scan-assembler "\[^0-9-\]8\\(%ebp\\),\[^\n\]*fooparam," } } */
+/* { dg-final { scan-assembler "\[^0-9-\]8\\(%ebp\\),\[^\n\]*barparam," } } */
+/* { dg-final { scan-assembler "\[^0-9-\]8\\(%ebp\\),\[^\n\]*foo2param," } } */
+/* { dg-final { scan-assembler "\[^0-9-\]8\\(%ebp\\),\[^\n\]*bar2param," } } */
+
+static inline int foo (int fooparam)
+{
+  return fooparam;
+}
+
+static int bar (int barparam)
+{
+  return foo (barparam);
+}
+
+static inline double foo2 (double foo2param)
+{
+  return foo2param;
+}
+
+static double bar2 (double bar2param)
+{
+  return foo2 (bar2param);
+}
+
+int
+main ()
+{
+  return bar (0) + bar2 (0.0);
+}
--- gcc/testsuite/g++.dg/other/pr39496.C.jj	2009-03-19 08:41:28.000000000 +0100
+++ gcc/testsuite/g++.dg/other/pr39496.C	2009-03-19 08:50:28.000000000 +0100
@@ -0,0 +1,35 @@
+// PR target/39496
+// { dg-do compile { target { { i?86-*-linux* x86_64-*-linux* } && ilp32 } } }
+// { dg-options "-O0 -fverbose-asm -fno-omit-frame-pointer -msse2 -mfpmath=sse" }
+// Verify that {foo,bar}{,2}param are all passed on the stack, using
+// normal calling conventions, when not optimizing.
+// { dg-final { scan-assembler "\[^0-9-\]8\\(%ebp\\),\[^\n\]*fooparam," } }
+// { dg-final { scan-assembler "\[^0-9-\]8\\(%ebp\\),\[^\n\]*barparam," } }
+// { dg-final { scan-assembler "\[^0-9-\]8\\(%ebp\\),\[^\n\]*foo2param," } }
+// { dg-final { scan-assembler "\[^0-9-\]8\\(%ebp\\),\[^\n\]*bar2param," } }
+
+static inline int foo (int fooparam)
+{
+  return fooparam;
+}
+
+static int bar (int barparam)
+{
+  return foo (barparam);
+}
+
+static inline double foo2 (double foo2param)
+{
+  return foo2param;
+}
+
+static double bar2 (double bar2param)
+{
+  return foo2 (bar2param);
+}
+
+int
+main ()
+{
+  return bar (0) + bar2 (0.0);
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]