+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
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;
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));