Hi, Recent changes to the lowerings for call handling in rs6000 have broken bootstrap for powerpc-darwin.
I’m proposing two patches; 1. the minimal fix to bootstrap - which I believe also fixes some possible typos in the patterns for sysv. 2. a second patch that brings Darwin into line with Alan’s recent change, and makes it hopefully clearer what can be done if/when we retire the mlongcall optimisation that is used for older Darwin versions. === The first patch makes Darwin share the sysv lowering, up until late in the process when we still use the macho_call_template. This means we need to preserve the CALL_LONG flag for Darwin. In order to match this for Darwin64, the sysv patterns needed the clobber mode to follow that of the pattern. It seems that this might be a typo - since it’s not obvious how it would work for powerpc64 sysv as things stand (AIX and ELFv2 already follow the mode). OK for trunk / comments? Iain gcc/ * config/rs6000/darwin.md (call_indirect_nonlocal_darwin64): Remove. (call_nonlocal_darwin64): Remove. (call_value_indirect_nonlocal_darwin64): Remove. (call_value_nonlocal_darwin64): Remove. * config/rs6000/rs6000.c (rs6000_call_template_1): Handle Darwin with the same asm output as AIX/ELFv2. (rs6000_call_sysv): Preserve the CALL_LONG flag when needed for Darwin. * config/rs6000/rs6000.md (define expand “call”): Expand Darwin as per sysv. (define_expand “call_value”): Likewise. (define_insn “call_indirect_nonlocal_sysv”): adjust clobber to take mode P. (call_nonlocal_sysv_secure): Likewise. (call_value_indirect_nonlocal_sysv): Likewise. (call_value_nonlocal_sysv): Likewise. (define_expand “sibcall”): Treat Darwin the same way as sysv. From 38ea0dbe42816b4c464b64b68b5fd5140b1a8dea Mon Sep 17 00:00:00 2001 From: Iain Sandoe <i...@sandoe.co.uk> Date: Fri, 30 Nov 2018 09:10:43 +0000 Subject: [PATCH] [PATCH,PPC] Fix up revised call handling for Darwin. --- gcc/config/rs6000/darwin.md | 60 ------------------------------------- gcc/config/rs6000/rs6000.c | 13 ++++++-- gcc/config/rs6000/rs6000.md | 19 ++++++------ 3 files changed, 20 insertions(+), 72 deletions(-) diff --git a/gcc/config/rs6000/darwin.md b/gcc/config/rs6000/darwin.md index a1c07702d6..ff8062c110 100644 --- a/gcc/config/rs6000/darwin.md +++ b/gcc/config/rs6000/darwin.md @@ -300,66 +300,6 @@ You should have received a copy of the GNU General Public License "addis %0,%1,ha16(%2-%3)\n\taddi %0,%0,lo16(%2-%3)" [(set_attr "length" "8")]) -(define_insn "*call_indirect_nonlocal_darwin64" - [(call (mem:SI (match_operand:DI 0 "register_operand" "c,*l,c,*l")) - (match_operand 1)) - (use (match_operand:SI 2 "immediate_operand" "O,O,n,n")) - (clobber (reg:SI LR_REGNO))] - "DEFAULT_ABI == ABI_DARWIN && TARGET_64BIT" -{ - return "b%T0l"; -} - [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg") - (set_attr "length" "4,4,8,8")]) - -(define_insn "*call_nonlocal_darwin64" - [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s,s")) - (match_operand 1)) - (use (match_operand:SI 2 "immediate_operand" "O,n")) - (clobber (reg:SI LR_REGNO))] - "(DEFAULT_ABI == ABI_DARWIN) - && (INTVAL (operands[2]) & CALL_LONG) == 0" -{ -#if TARGET_MACHO - return output_call(insn, operands, 0, 2); -#else - gcc_unreachable (); -#endif -} - [(set_attr "type" "branch,branch") - (set_attr "length" "4,8")]) - -(define_insn "*call_value_indirect_nonlocal_darwin64" - [(set (match_operand 0 "" "") - (call (mem:SI (match_operand:DI 1 "register_operand" "c,*l,c,*l")) - (match_operand 2))) - (use (match_operand:SI 3 "immediate_operand" "O,O,n,n")) - (clobber (reg:SI LR_REGNO))] - "DEFAULT_ABI == ABI_DARWIN" -{ - return "b%T1l"; -} - [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg") - (set_attr "length" "4,4,8,8")]) - -(define_insn "*call_value_nonlocal_darwin64" - [(set (match_operand 0 "" "") - (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s,s")) - (match_operand 2))) - (use (match_operand:SI 3 "immediate_operand" "O,n")) - (clobber (reg:SI LR_REGNO))] - "(DEFAULT_ABI == ABI_DARWIN) - && (INTVAL (operands[3]) & CALL_LONG) == 0" -{ -#if TARGET_MACHO - return output_call(insn, operands, 1, 3); -#else - gcc_unreachable (); -#endif -} - [(set_attr "type" "branch,branch") - (set_attr "length" "4,8")]) - (define_expand "reload_macho_picbase" [(set (reg:SI LR_REGNO) (unspec [(match_operand 0 "")] diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 03b983b6d6..bce968516c 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -21513,7 +21513,8 @@ rs6000_call_template_1 (rtx *operands, unsigned int funop, bool sibcall) ? "+32768" : "")); static char str[32]; /* 2 spare */ - if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2) + if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2 + || DEFAULT_ABI == ABI_DARWIN) sprintf (str, "b%s %s%s%s", sibcall ? "" : "l", z, arg, sibcall ? "" : "\n\tnop"); else if (DEFAULT_ABI == ABI_V4) @@ -37937,6 +37938,7 @@ rs6000_call_sysv (rtx value, rtx func_desc, rtx tlsarg, rtx cookie) /* Handle longcall attributes. */ if ((INTVAL (cookie) & CALL_LONG) != 0 + && DEFAULT_ABI != ABI_DARWIN /* Darwin does it's own thing. */ && GET_CODE (func_desc) == SYMBOL_REF) { func = rs6000_longcall_ref (func_desc, tlsarg); @@ -37977,8 +37979,13 @@ rs6000_call_sysv (rtx value, rtx func_desc, rtx tlsarg, rtx cookie) if (value != NULL_RTX) call[0] = gen_rtx_SET (value, call[0]); - unsigned int mask = CALL_V4_SET_FP_ARGS | CALL_V4_CLEAR_FP_ARGS; - call[1] = gen_rtx_USE (VOIDmode, GEN_INT (INTVAL (cookie) & mask)); + if (DEFAULT_ABI == ABI_DARWIN && TARGET_32BIT) + call[1] = gen_rtx_USE (VOIDmode, GEN_INT (INTVAL (cookie))); + else + { + unsigned int mask = CALL_V4_SET_FP_ARGS | CALL_V4_CLEAR_FP_ARGS; + call[1] = gen_rtx_USE (VOIDmode, GEN_INT (INTVAL (cookie) & mask)); + } call[2] = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, LR_REGNO)); diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md index 797d5c32e6..d684bed3ae 100644 --- a/gcc/config/rs6000/rs6000.md +++ b/gcc/config/rs6000/rs6000.md @@ -10266,6 +10266,7 @@ }) ;; Call and call_value insns +;; For the purposes of expanding calls, Darwin is very similar to SYSV. (define_expand "call" [(parallel [(call (mem:SI (match_operand 0 "address_operand")) (match_operand 1 "")) @@ -10288,7 +10289,7 @@ DONE; } - if (DEFAULT_ABI == ABI_V4) + if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_DARWIN) { rs6000_call_sysv (NULL_RTX, operands[0], operands[1], operands[2]); DONE; @@ -10321,7 +10322,7 @@ DONE; } - if (DEFAULT_ABI == ABI_V4) + if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_DARWIN) { rs6000_call_sysv (operands[0], operands[1], operands[2], operands[3]); DONE; @@ -10423,7 +10424,7 @@ [(call (mem:SI (match_operand:P 0 "indirect_call_operand" "c,*l,X")) (match_operand 1)) (use (match_operand:SI 2 "immediate_operand" "n,n,n")) - (clobber (reg:SI LR_REGNO))] + (clobber (reg:P LR_REGNO))] "DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_DARWIN" { @@ -10451,7 +10452,7 @@ [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s")) (match_operand 1)) (use (match_operand:SI 2 "immediate_operand" "O,n")) - (clobber (reg:SI LR_REGNO))] + (clobber (reg:P LR_REGNO))] "(DEFAULT_ABI == ABI_DARWIN || (DEFAULT_ABI == ABI_V4 && (INTVAL (operands[2]) & CALL_LONG) == 0))" @@ -10487,7 +10488,7 @@ (match_operand 1)) (use (match_operand:SI 2 "immediate_operand" "O,n")) (use (match_operand:SI 3 "register_operand" "r,r")) - (clobber (reg:SI LR_REGNO))] + (clobber (reg:P LR_REGNO))] "(DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0]) && (INTVAL (operands[2]) & CALL_LONG) == 0)" @@ -10508,7 +10509,7 @@ (call (mem:SI (match_operand:P 1 "indirect_call_operand" "c,*l,X")) (match_operand 2))) (use (match_operand:SI 3 "immediate_operand" "n,n,n")) - (clobber (reg:SI LR_REGNO))] + (clobber (reg:P LR_REGNO))] "DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_DARWIN" { @@ -10537,7 +10538,7 @@ (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s")) (match_operand 2))) (use (match_operand:SI 3 "immediate_operand" "O,n")) - (clobber (reg:SI LR_REGNO))] + (clobber (reg:P LR_REGNO))] "(DEFAULT_ABI == ABI_DARWIN || (DEFAULT_ABI == ABI_V4 && (INTVAL (operands[3]) & CALL_LONG) == 0))" @@ -10765,7 +10766,7 @@ DONE; } - if (DEFAULT_ABI == ABI_V4) + if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_DARWIN) { rs6000_sibcall_sysv (NULL_RTX, operands[0], operands[1], operands[2]); DONE; @@ -10796,7 +10797,7 @@ DONE; } - if (DEFAULT_ABI == ABI_V4) + if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_DARWIN) { rs6000_sibcall_sysv (operands[0], operands[1], operands[2], operands[3]); DONE; -- 2.17.1