diff mbox series

rs6000: Make CSE'ing __tls_get_addr calls possible

Message ID c8e9a1da0f0dfeab3038a1fe827226ce2a78bee8.1553382163.git.segher@kernel.crashing.org
State New
Headers show
Series rs6000: Make CSE'ing __tls_get_addr calls possible | expand

Commit Message

Segher Boessenkool March 23, 2019, 11:46 p.m. UTC
CSE does not consider calls, not even const calls.  This patch puts a
REG_EQUAL note on the pseudo we assign the __tls_get_addr result to,
so that those pseudos can be CSE'd and the extra calls deleted as dead
code.

CSE should really handle const calls directly, but it is stage 4.

Tested on powerpc64-linux {-m32,-m64}.  I'll also test on powerpc64le-linux,
and will commit it to trunk if that works.


Segher


2019-03-23  Segher Boessenkool  <segher@kernel.crashing.org>

	* config/rs6000/rs6000.c (rs6000_legitimize_tls_address): Add REG_EQUAL
	notes for the result of the __tls_get_addr calls.
	* config/rs6000/rs6000.md (unspec UNSPEC_TLS_GET_ADDR): New.

---
 gcc/config/rs6000/rs6000.c  | 10 ++++++++++
 gcc/config/rs6000/rs6000.md |  1 +
 2 files changed, 11 insertions(+)

Comments

Steven Bosscher March 24, 2019, 10:02 a.m. UTC | #1
On Sun, Mar 24, 2019 at 12:46 AM Segher Boessenkool wrote:
>
> CSE does not consider calls, not even const calls.  This patch puts a
> REG_EQUAL note on the pseudo we assign the __tls_get_addr result to,
> so that those pseudos can be CSE'd and the extra calls deleted as dead
> code.

Hi Segher,

There were REG_EQUAL notes on these tls calls in the past, but I
recall removing them for one reason or another. So watch out for
fall-out from this patch! ;-)

Ciao!
Steven
Segher Boessenkool March 24, 2019, 4:18 p.m. UTC | #2
Hi Steven,

On Sun, Mar 24, 2019 at 11:02:20AM +0100, Steven Bosscher wrote:
> On Sun, Mar 24, 2019 at 12:46 AM Segher Boessenkool wrote:
> >
> > CSE does not consider calls, not even const calls.  This patch puts a
> > REG_EQUAL note on the pseudo we assign the __tls_get_addr result to,
> > so that those pseudos can be CSE'd and the extra calls deleted as dead
> > code.
> 
> There were REG_EQUAL notes on these tls calls in the past, but I
> recall removing them for one reason or another.

I cannot find this in history.  History is pretty big of course, so perhaps
I'm not looking at the right corner :-)

> So watch out for
> fall-out from this patch! ;-)

Thanks for the warning!

The patch doesn't change anything, in the sense that these calls were const
calls before already, but yeah :-)


Segher
Eric Botcazou March 24, 2019, 11:25 p.m. UTC | #3
> There were REG_EQUAL notes on these tls calls in the past, but I
> recall removing them for one reason or another. So watch out for
> fall-out from this patch! ;-)

Others ports have them though, for example i386, ARM and SPARC.
Segher Boessenkool Aug. 31, 2019, 7:17 p.m. UTC | #4
Hi all,

On Sat, Mar 23, 2019 at 11:46:12PM +0000, Segher Boessenkool wrote:
> CSE does not consider calls, not even const calls.  This patch puts a
> REG_EQUAL note on the pseudo we assign the __tls_get_addr result to,
> so that those pseudos can be CSE'd and the extra calls deleted as dead
> code.
> 
> CSE should really handle const calls directly, but it is stage 4.

I am backporting this to GCC 8.


Segher


> 2019-03-23  Segher Boessenkool  <segher@kernel.crashing.org>
> 
> 	* config/rs6000/rs6000.c (rs6000_legitimize_tls_address): Add REG_EQUAL
> 	notes for the result of the __tls_get_addr calls.
> 	* config/rs6000/rs6000.md (unspec UNSPEC_TLS_GET_ADDR): New.
> 
> ---
>  gcc/config/rs6000/rs6000.c  | 10 ++++++++++
>  gcc/config/rs6000/rs6000.md |  1 +
>  2 files changed, 11 insertions(+)
> 
> diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
> index 15811bd..35aedf4 100644
> --- a/gcc/config/rs6000/rs6000.c
> +++ b/gcc/config/rs6000/rs6000.c
> @@ -8661,6 +8661,11 @@ rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
>  	  else
>  	    emit_library_call_value (tga, dest, LCT_CONST, Pmode);
>  	  global_tlsarg = NULL_RTX;
> +
> +	  /* Make a note so that the result of this call can be CSEd.  */
> +	  rtvec vec = gen_rtvec (1, copy_rtx (arg));
> +	  rtx uns = gen_rtx_UNSPEC (Pmode, vec, UNSPEC_TLS_GET_ADDR);
> +	  set_unique_reg_note (get_last_insn (), REG_EQUAL, uns);
>  	}
>        else if (model == TLS_MODEL_LOCAL_DYNAMIC)
>  	{
> @@ -8679,6 +8684,11 @@ rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
>  	    emit_library_call_value (tga, tmp1, LCT_CONST, Pmode);
>  	  global_tlsarg = NULL_RTX;
>  
> +	  /* Make a note so that the result of this call can be CSEd.  */
> +	  rtvec vec = gen_rtvec (1, copy_rtx (arg));
> +	  rtx uns = gen_rtx_UNSPEC (Pmode, vec, UNSPEC_TLS_GET_ADDR);
> +	  set_unique_reg_note (get_last_insn (), REG_EQUAL, uns);
> +
>  	  if (rs6000_tls_size == 16)
>  	    {
>  	      if (TARGET_64BIT)
> diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
> index f2faef8..815077c 100644
> --- a/gcc/config/rs6000/rs6000.md
> +++ b/gcc/config/rs6000/rs6000.md
> @@ -79,6 +79,7 @@ (define_c_enum "unspec"
>     UNSPEC_MPIC_CORRECT		; macho_correct_pic
>     UNSPEC_TLSGD
>     UNSPEC_TLSLD
> +   UNSPEC_TLS_GET_ADDR
>     UNSPEC_MOVESI_FROM_CR
>     UNSPEC_MOVESI_TO_CR
>     UNSPEC_TLSDTPREL
> -- 
> 1.8.3.1
Segher Boessenkool Aug. 31, 2019, 8:14 p.m. UTC | #5
On Sat, Aug 31, 2019 at 02:17:30PM -0500, Segher Boessenkool wrote:
> Hi all,
> 
> On Sat, Mar 23, 2019 at 11:46:12PM +0000, Segher Boessenkool wrote:
> > CSE does not consider calls, not even const calls.  This patch puts a
> > REG_EQUAL note on the pseudo we assign the __tls_get_addr result to,
> > so that those pseudos can be CSE'd and the extra calls deleted as dead
> > code.
> > 
> > CSE should really handle const calls directly, but it is stage 4.
> 
> I am backporting this to GCC 8.

Actually, that is not trivial at all, so I'm not doing that.


Segher
diff mbox series

Patch

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 15811bd..35aedf4 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -8661,6 +8661,11 @@  rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
 	  else
 	    emit_library_call_value (tga, dest, LCT_CONST, Pmode);
 	  global_tlsarg = NULL_RTX;
+
+	  /* Make a note so that the result of this call can be CSEd.  */
+	  rtvec vec = gen_rtvec (1, copy_rtx (arg));
+	  rtx uns = gen_rtx_UNSPEC (Pmode, vec, UNSPEC_TLS_GET_ADDR);
+	  set_unique_reg_note (get_last_insn (), REG_EQUAL, uns);
 	}
       else if (model == TLS_MODEL_LOCAL_DYNAMIC)
 	{
@@ -8679,6 +8684,11 @@  rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
 	    emit_library_call_value (tga, tmp1, LCT_CONST, Pmode);
 	  global_tlsarg = NULL_RTX;
 
+	  /* Make a note so that the result of this call can be CSEd.  */
+	  rtvec vec = gen_rtvec (1, copy_rtx (arg));
+	  rtx uns = gen_rtx_UNSPEC (Pmode, vec, UNSPEC_TLS_GET_ADDR);
+	  set_unique_reg_note (get_last_insn (), REG_EQUAL, uns);
+
 	  if (rs6000_tls_size == 16)
 	    {
 	      if (TARGET_64BIT)
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index f2faef8..815077c 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -79,6 +79,7 @@  (define_c_enum "unspec"
    UNSPEC_MPIC_CORRECT		; macho_correct_pic
    UNSPEC_TLSGD
    UNSPEC_TLSLD
+   UNSPEC_TLS_GET_ADDR
    UNSPEC_MOVESI_FROM_CR
    UNSPEC_MOVESI_TO_CR
    UNSPEC_TLSDTPREL