rs6000.c (rs6000_call_aix): For the AIX ABI, do not load the static chain if the...
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 25 Nov 2014 09:07:25 +0000 (09:07 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Tue, 25 Nov 2014 09:07:25 +0000 (09:07 +0000)
* config/rs6000/rs6000.c (rs6000_call_aix): For the AIX ABI, do not
load the static chain if the call was originally direct.

From-SVN: r218040

gcc/ChangeLog
gcc/config/rs6000/rs6000.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/powerpc/longcall-2.c [new file with mode: 0644]

index 8ff9c72..bed7cb8 100644 (file)
@@ -1,3 +1,8 @@
+2014-11-25  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * config/rs6000/rs6000.c (rs6000_call_aix): For the AIX ABI, do not
+       load the static chain if the call was originally direct.
+
 2014-11-25  Jan Hubicka  <hubicka@ucw.cz>
 
        PR ipa/64059
index a87e762..6873c77 100644 (file)
@@ -32853,6 +32853,8 @@ rs6000_legitimate_constant_p (machine_mode mode, rtx x)
 void
 rs6000_call_aix (rtx value, rtx func_desc, rtx flag, rtx cookie)
 {
+  const bool direct_call_p
+    = GET_CODE (func_desc) == SYMBOL_REF && SYMBOL_REF_FUNCTION_P (func_desc);
   rtx toc_reg = gen_rtx_REG (Pmode, TOC_REGNUM);
   rtx toc_load = NULL_RTX;
   rtx toc_restore = NULL_RTX;
@@ -32921,8 +32923,11 @@ rs6000_call_aix (rtx value, rtx func_desc, rtx flag, rtx cookie)
                                                        func_toc_offset));
          toc_load = gen_rtx_USE (VOIDmode, func_toc_mem);
 
-         /* If we have a static chain, load it up.  */
-         if (TARGET_POINTERS_TO_NESTED_FUNCTIONS)
+         /* If we have a static chain, load it up.  But, if the call was
+            originally direct, the 3rd word has not been written since no
+            trampoline has been built, so we ought not to load it, lest we
+            override a static chain value.  */
+         if (!direct_call_p && TARGET_POINTERS_TO_NESTED_FUNCTIONS)
            {
              rtx sc_reg = gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM);
              rtx func_sc_offset = GEN_INT (2 * GET_MODE_SIZE (Pmode));
index 4a8d7cd..6f96bfb 100644 (file)
@@ -1,3 +1,7 @@
+2014-10-25  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc.target/powerpc/longcall-2.c: New test.
+
 2014-11-25  Marek Polacek  <polacek@redhat.com>
 
        PR c/63877
diff --git a/gcc/testsuite/gcc.target/powerpc/longcall-2.c b/gcc/testsuite/gcc.target/powerpc/longcall-2.c
new file mode 100644 (file)
index 0000000..fc73cee
--- /dev/null
@@ -0,0 +1,32 @@
+/* { dg-do run } */
+/* { dg-options "-mlongcall" } */
+
+extern void abort (void);
+
+#define VAL 12345678
+
+int j = VAL;
+
+void
+bar (void)
+{
+  if (j != VAL)
+    abort ();
+}
+
+int
+main (void)
+{
+  int i = VAL;
+
+  int foo (void)
+  {
+    if (i != VAL)
+      abort ();
+  }
+
+  foo ();
+  bar ();
+
+  return 0;
+}