From 8fc9dbfb8b6fb0cd39b2c8fef8c70a028ff5497f Mon Sep 17 00:00:00 2001 From: amodra Date: Thu, 5 Feb 2015 22:52:24 +0000 Subject: [PATCH] PR target/64876 * config/rs6000/rs6000.c (chain_already_loaded): New function. (rs6000_call_aix): Use it. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@220463 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/config/rs6000/rs6000.c | 26 +++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b4c14d1d1b6..90cee313a26 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-02-06 Alan Modra + + PR target/64876 + * config/rs6000/rs6000.c (chain_already_loaded): New function. + (rs6000_call_aix): Use it. + 2015-02-05 Jan Hubicka * ipa-cp.c (ipa_value_from_jfunc, ipa_context_from_jfunc): Add bounds diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 356955ab8bb..4f88328a506 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -32919,6 +32919,28 @@ rs6000_legitimate_constant_p (machine_mode mode, rtx x) } +/* Return TRUE iff the sequence ending in LAST sets the static chain. */ + +static bool +chain_already_loaded (rtx_insn *last) +{ + for (; last != NULL; last = PREV_INSN (last)) + { + if (NONJUMP_INSN_P (last)) + { + rtx patt = PATTERN (last); + + if (GET_CODE (patt) == SET) + { + rtx lhs = XEXP (patt, 0); + + if (REG_P (lhs) && REGNO (lhs) == STATIC_CHAIN_REGNUM) + return true; + } + } + } + return false; +} /* Expand code to perform a call under the AIX or ELFv2 ABI. */ @@ -33002,7 +33024,9 @@ rs6000_call_aix (rtx value, rtx func_desc, rtx flag, rtx cookie) 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) + if (!direct_call_p + && TARGET_POINTERS_TO_NESTED_FUNCTIONS + && !chain_already_loaded (crtl->emit.sequence_stack->last)) { rtx sc_reg = gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM); rtx func_sc_offset = GEN_INT (2 * GET_MODE_SIZE (Pmode)); -- 2.11.4.GIT