[RS6000] Put call cookie back in AIX/ELFv2 call patterns
authorAlan Modra <amodra@gmail.com>
Fri, 27 Mar 2020 02:42:34 +0000 (13:12 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 30 Mar 2020 07:39:05 +0000 (18:09 +1030)
-mlongcall -mno-pltseq is supposed to emit long calls by using
indirect calls.  It differs from -mlongcall -mpltseq in that the
function addresses are not placed in the PLT and thus lazy PLT
resolution is not available, affecting programs that dlopen shared
libraries.

In the case of -mcpu=future -mpcrel -mlongcall -mno-pltseq we see an
indirect call being generated, but combine merrily optimises the
sequence back to a direct call.  call_indirect_pcrel is enough like
call_nonlocal_aix that this can happen.

This patch puts the call cookie back in the call rtl, removed by git
commit f90f960ca8, in order to disable the optimisation for long
calls.  When that is done for call_local_aix the pattern becomes the
same as call_local32/64, so I merged them.  The only difference
besides mode between call_local32 and call_local64, dating back to
1998 commit a260abc996, is that call_local64 has TARGET_64BIT in the
predicate.  That alone doesn't seem reason enough to need separate
patterns; The P mode iterator selects DI on TARGET_64BIT anyway.

* config/rs6000/rs6000.c (rs6000_call_aix): Emit cookie to pattern.
(rs6000_indirect_call_template_1): Adjust to suit.
* config/rs6000/rs6000.md (call_local): Merge call_local32,
call_local64, and call_local_aix.
(call_value_local): Simlarly.
(call_nonlocal_aix, call_value_nonlocal_aix): Adjust rtl to suit,
and disable pattern when CALL_LONG.
(call_indirect_aix, call_value_indirect_aix): Adjust rtl.
(call_indirect_elfv2, call_indirect_pcrel): Likewise.
(call_value_indirect_elfv2, call_value_indirect_pcrel): Likewise.

gcc/ChangeLog
gcc/config/rs6000/rs6000.c
gcc/config/rs6000/rs6000.md

index 29900e1..4e0545d 100644 (file)
@@ -1,3 +1,16 @@
+2020-03-30  Alan Modra  <amodra@gmail.com>
+
+       * config/rs6000/rs6000.c (rs6000_call_aix): Emit cookie to pattern.
+       (rs6000_indirect_call_template_1): Adjust to suit.
+       * config/rs6000/rs6000.md (call_local): Merge call_local32,
+       call_local64, and call_local_aix.
+       (call_value_local): Simlarly.
+       (call_nonlocal_aix, call_value_nonlocal_aix): Adjust rtl to suit,
+       and disable pattern when CALL_LONG.
+       (call_indirect_aix, call_value_indirect_aix): Adjust rtl.
+       (call_indirect_elfv2, call_indirect_pcrel): Likewise.
+       (call_value_indirect_elfv2, call_value_indirect_pcrel): Likewise.
+
 2020-03-29  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR driver/94381
index 13851d1..2b6613b 100644 (file)
@@ -13621,7 +13621,7 @@ rs6000_indirect_call_template_1 (rtx *operands, unsigned int funop,
   if (DEFAULT_ABI == ABI_AIX)
     s += sprintf (s,
                  "l%s 2,%%%u\n\t",
-                 ptrload, funop + 2);
+                 ptrload, funop + 3);
 
   /* We don't need the extra code to stop indirect call speculation if
      calling via LR.  */
@@ -13675,12 +13675,12 @@ rs6000_indirect_call_template_1 (rtx *operands, unsigned int funop,
        sprintf (s,
                 "b%%T%ul\n\t"
                 "l%s 2,%%%u(1)",
-                funop, ptrload, funop + 3);
+                funop, ptrload, funop + 4);
       else
        sprintf (s,
                 "beq%%T%ul-\n\t"
                 "l%s 2,%%%u(1)",
-                funop, ptrload, funop + 3);
+                funop, ptrload, funop + 4);
     }
   else if (DEFAULT_ABI == ABI_ELFv2)
     {
@@ -13688,12 +13688,12 @@ rs6000_indirect_call_template_1 (rtx *operands, unsigned int funop,
        sprintf (s,
                 "b%%T%ul\n\t"
                 "l%s 2,%%%u(1)",
-                funop, ptrload, funop + 2);
+                funop, ptrload, funop + 3);
       else
        sprintf (s,
                 "beq%%T%ul-\n\t"
                 "l%s 2,%%%u(1)",
-                funop, ptrload, funop + 2);
+                funop, ptrload, funop + 3);
     }
   else
     {
@@ -24304,7 +24304,7 @@ rs6000_call_aix (rtx value, rtx func_desc, rtx tlsarg, rtx cookie)
   rtx toc_restore = NULL_RTX;
   rtx func_addr;
   rtx abi_reg = NULL_RTX;
-  rtx call[4];
+  rtx call[5];
   int n_call;
   rtx insn;
   bool is_pltseq_longcall;
@@ -24445,7 +24445,8 @@ rs6000_call_aix (rtx value, rtx func_desc, rtx tlsarg, rtx cookie)
   call[0] = gen_rtx_CALL (VOIDmode, gen_rtx_MEM (SImode, func_addr), tlsarg);
   if (value != NULL_RTX)
     call[0] = gen_rtx_SET (value, call[0]);
-  n_call = 1;
+  call[1] = gen_rtx_USE (VOIDmode, cookie);
+  n_call = 2;
 
   if (toc_load)
     call[n_call++] = toc_load;
index 5a8e9de..dcccb03 100644 (file)
 ;; variable argument function.  It is > 0 if FP registers were passed
 ;; and < 0 if they were not.
 
-(define_insn "*call_local32"
-  [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
+(define_insn "*call_local<mode>"
+  [(call (mem:SI (match_operand:P 0 "current_file_function_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))]
   "(INTVAL (operands[2]) & CALL_LONG) == 0"
 {
   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
     output_asm_insn ("creqv 6,6,6", operands);
 
+  if (rs6000_pcrel_p (cfun))
+    return "bl %z0@notoc";
   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z0@local" : "bl %z0";
 }
   [(set_attr "type" "branch")
    (set_attr "length" "4,8")])
 
-(define_insn "*call_local64"
-  [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
-        (match_operand 1))
-   (use (match_operand:SI 2 "immediate_operand" "O,n"))
-   (clobber (reg:DI LR_REGNO))]
-  "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
-{
-  if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
-    output_asm_insn ("crxor 6,6,6", operands);
-
-  else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
-    output_asm_insn ("creqv 6,6,6", operands);
-
-  return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z0@local" : "bl %z0";
-}
-  [(set_attr "type" "branch")
-   (set_attr "length" "4,8")])
-
-(define_insn "*call_value_local32"
+(define_insn "*call_value_local<mode>"
   [(set (match_operand 0 "" "")
-       (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
+       (call (mem:SI (match_operand:P 1 "current_file_function_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))]
   "(INTVAL (operands[3]) & CALL_LONG) == 0"
 {
   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
     output_asm_insn ("creqv 6,6,6", operands);
 
-  return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z1@local" : "bl %z1";
-}
-  [(set_attr "type" "branch")
-   (set_attr "length" "4,8")])
-
-
-(define_insn "*call_value_local64"
-  [(set (match_operand 0 "" "")
-       (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
-             (match_operand 2)))
-   (use (match_operand:SI 3 "immediate_operand" "O,n"))
-   (clobber (reg:DI LR_REGNO))]
-  "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
-{
-  if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
-    output_asm_insn ("crxor 6,6,6", operands);
-
-  else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
-    output_asm_insn ("creqv 6,6,6", operands);
-
+  if (rs6000_pcrel_p (cfun))
+    return "bl %z1@notoc";
   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z1@local" : "bl %z1";
 }
   [(set_attr "type" "branch")
          (const_int 8)
          (const_int 4)))])
 
-;; Call to AIX abi function in the same module.
-
-(define_insn "*call_local_aix<mode>"
-  [(call (mem:SI (match_operand:P 0 "current_file_function_operand" "s"))
-        (match_operand 1))
-   (clobber (reg:P LR_REGNO))]
-  "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
-{
-  if (rs6000_pcrel_p (cfun))
-    return "bl %z0@notoc";
-  return "bl %z0";
-}
-  [(set_attr "type" "branch")])
-
-(define_insn "*call_value_local_aix<mode>"
-  [(set (match_operand 0 "" "")
-       (call (mem:SI (match_operand:P 1 "current_file_function_operand" "s"))
-             (match_operand 2)))
-   (clobber (reg:P LR_REGNO))]
-  "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
-{
-  if (rs6000_pcrel_p (cfun))
-    return "bl %z1@notoc";
-  return "bl %z1";
-}
-  [(set_attr "type" "branch")])
-
 ;; Call to AIX abi function which may be in another module.
 ;; Restore the TOC pointer (r2) after the call.
 
 (define_insn "*call_nonlocal_aix<mode>"
   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s"))
         (match_operand 1))
+   (use (match_operand:SI 2 "immediate_operand" "n"))
    (clobber (reg:P LR_REGNO))]
-  "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
+  "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
+   && (INTVAL (operands[2]) & CALL_LONG) == 0"
 {
   return rs6000_call_template (operands, 0);
 }
   [(set (match_operand 0 "" "")
        (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s"))
              (match_operand:P 2 "unspec_tls" "")))
+   (use (match_operand:SI 3 "immediate_operand" "n"))
    (clobber (reg:P LR_REGNO))]
-  "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
+  "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
+   && (INTVAL (operands[3]) & CALL_LONG) == 0"
 {
   return rs6000_call_template (operands, 1);
 }
 
 ;; Call to indirect functions with the AIX abi using a 3 word descriptor.
 ;; Operand0 is the addresss of the function to call
-;; Operand2 is the location in the function descriptor to load r2 from
-;; Operand3 is the offset of the stack location holding the current TOC pointer
+;; Operand3 is the location in the function descriptor to load r2 from
+;; Operand4 is the offset of the stack location holding the current TOC pointer
 
 (define_insn "*call_indirect_aix<mode>"
   [(call (mem:SI (match_operand:P 0 "indirect_call_operand" "c,*l,X"))
         (match_operand 1))
-   (use (match_operand:P 2 "memory_operand" "<ptrm>,<ptrm>,<ptrm>"))
-   (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 3 "const_int_operand" "n,n,n")] UNSPEC_TOCSLOT))
+   (use (match_operand:SI 2 "immediate_operand" "n,n,n"))
+   (use (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>,<ptrm>"))
+   (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 4 "const_int_operand" "n,n,n")] UNSPEC_TOCSLOT))
    (clobber (reg:P LR_REGNO))]
   "DEFAULT_ABI == ABI_AIX"
 {
   [(set (match_operand 0 "" "")
        (call (mem:SI (match_operand:P 1 "indirect_call_operand" "c,*l,X"))
              (match_operand:P 2 "unspec_tls" "")))
-   (use (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>,<ptrm>"))
+   (use (match_operand:SI 3 "immediate_operand" "n,n,n"))
+   (use (match_operand:P 4 "memory_operand" "<ptrm>,<ptrm>,<ptrm>"))
    (set (reg:P TOC_REGNUM)
-       (unspec:P [(match_operand:P 4 "const_int_operand" "n,n,n")]
+       (unspec:P [(match_operand:P 5 "const_int_operand" "n,n,n")]
                  UNSPEC_TOCSLOT))
    (clobber (reg:P LR_REGNO))]
   "DEFAULT_ABI == ABI_AIX"
 
 ;; Call to indirect functions with the ELFv2 ABI.
 ;; Operand0 is the addresss of the function to call
-;; Operand2 is the offset of the stack location holding the current TOC pointer
+;; Operand3 is the offset of the stack location holding the current TOC pointer
 
 (define_insn "*call_indirect_elfv2<mode>"
   [(call (mem:SI (match_operand:P 0 "indirect_call_operand" "c,*l,X"))
         (match_operand 1))
-   (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 2 "const_int_operand" "n,n,n")] UNSPEC_TOCSLOT))
+   (use (match_operand:SI 2 "immediate_operand" "n,n,n"))
+   (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 3 "const_int_operand" "n,n,n")] UNSPEC_TOCSLOT))
    (clobber (reg:P LR_REGNO))]
   "DEFAULT_ABI == ABI_ELFv2"
 {
 (define_insn "*call_indirect_pcrel<mode>"
   [(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:P LR_REGNO))]
   "rs6000_pcrel_p (cfun)"
 {
   [(set (match_operand 0 "" "")
        (call (mem:SI (match_operand:P 1 "indirect_call_operand" "c,*l,X"))
              (match_operand:P 2 "unspec_tls" "")))
+   (use (match_operand:SI 3 "immediate_operand" "n,n,n"))
    (set (reg:P TOC_REGNUM)
-       (unspec:P [(match_operand:P 3 "const_int_operand" "n,n,n")]
+       (unspec:P [(match_operand:P 4 "const_int_operand" "n,n,n")]
                  UNSPEC_TOCSLOT))
    (clobber (reg:P LR_REGNO))]
   "DEFAULT_ABI == ABI_ELFv2"
   [(set (match_operand 0 "" "")
        (call (mem:SI (match_operand:P 1 "indirect_call_operand" "c,*l,X"))
              (match_operand:P 2 "unspec_tls" "")))
+   (use (match_operand:SI 3 "immediate_operand" "n,n,n"))
    (clobber (reg:P LR_REGNO))]
   "rs6000_pcrel_p (cfun)"
 {