diff mbox series

[RS6000] Put call cookie back in AIX/ELFv2 call patterns

Message ID 20200327225709.GR4583@bubble.grove.modra.org
State New
Headers show
Series [RS6000] Put call cookie back in AIX/ELFv2 call patterns | expand

Commit Message

Li, Pan2 via Gcc-patches March 27, 2020, 10:57 p.m. UTC
-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.

Bootstrapped and regression tested powerpc64le-linux and
powerpc64-linux biarch all langs.  OK for master?

	* 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.

Comments

Segher Boessenkool March 28, 2020, 8:03 p.m. UTC | #1
Hi!

On Sat, Mar 28, 2020 at 09:27:09AM +1030, Alan Modra wrote:
> 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.

Yes, these patterns could be merged before this patch, already.

This patch would have been much easier to read / check if it had been
a short series, btw (with those independent cleanups done first).

But it looks fine.  Okay for trunk.  Thanks!


Segher


> 	* 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.
diff mbox series

Patch

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 13851d12551..2b6613bcb7e 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -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;
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 5a8e9de670b..dcccb03f376 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -10459,11 +10459,11 @@ 
 ;; 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)
@@ -10472,35 +10472,19 @@ 
   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)
@@ -10509,26 +10493,8 @@ 
   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")
@@ -10687,41 +10653,16 @@ 
 	  (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);
 }
@@ -10735,8 +10676,10 @@ 
   [(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);
 }
@@ -10748,14 +10691,15 @@ 
 
 ;; 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"
 {
@@ -10772,9 +10716,10 @@ 
   [(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"
@@ -10790,12 +10735,13 @@ 
 
 ;; 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"
 {
@@ -10811,6 +10757,7 @@ 
 (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)"
 {
@@ -10827,8 +10774,9 @@ 
   [(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"
@@ -10846,6 +10794,7 @@ 
   [(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)"
 {