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 <seg...@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