+2015-02-06 Alan Modra <amodra@gmail.com>
+
+ PR target/64876
+ * config/rs6000/rs6000.c (chain_already_loaded): New function.
+ (rs6000_call_aix): Use it.
+
2015-02-05 Jan Hubicka <hubicka@ucw.cz>
* ipa-cp.c (ipa_value_from_jfunc, ipa_context_from_jfunc): Add bounds
}
\f
+/* 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. */
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));