From 6358ab2451eb87e8715d846c07badf4c67b85cfc Mon Sep 17 00:00:00 2001 From: ebotcazou Date: Tue, 25 Nov 2014 09:07:25 +0000 Subject: [PATCH] * config/rs6000/rs6000.c (rs6000_call_aix): For the AIX ABI, do not load the static chain if the call was originally direct. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@218040 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 5 +++++ gcc/config/rs6000/rs6000.c | 9 ++++++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.target/powerpc/longcall-2.c | 32 +++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/longcall-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8ff9c72256d..bed7cb86ed3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2014-11-25 Eric Botcazou + + * 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 PR ipa/64059 diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index a87e762e56d..6873c77af7c 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -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)); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4a8d7cd3cea..6f96bfb6b92 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2014-10-25 Eric Botcazou + + * gcc.target/powerpc/longcall-2.c: New test. + 2014-11-25 Marek Polacek 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 index 00000000000..fc73cee3fb4 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/longcall-2.c @@ -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; +} -- 2.11.4.GIT