From: Ilya Leoshkevich Date: Thu, 24 Oct 2019 09:00:41 +0000 (+0000) Subject: S/390: Use UNSPEC_GET_TP for thread pointer loads X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8f4f98f617c117919ccf0abc324eb2e431e8e0b0;p=gcc.git S/390: Use UNSPEC_GET_TP for thread pointer loads gcc/ChangeLog: 2019-10-24 Ilya Leoshkevich * config/s390/s390.c (s390_get_thread_pointer): Use gen_get_thread_pointer. (s390_expand_split_stack_prologue): Likewise. * config/s390/s390.md (UNSPEC_GET_TP): New UNSPEC. (*get_tp_31): New 31-bit splitter for UNSPEC_GET_TP. (*get_tp_64): New 64-bit splitter for UNSPEC_GET_TP. (get_thread_pointer): Use UNSPEC_GET_TP, use parameterized name. gcc/testsuite/ChangeLog: 2019-10-24 Ilya Leoshkevich * gcc.target/s390/load-thread-pointer-once-2.c: New test. From-SVN: r277368 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9296d5d7236..e0c4c1759cd 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2019-10-24 Ilya Leoshkevich + + * config/s390/s390.c (s390_get_thread_pointer): Use + gen_get_thread_pointer. + (s390_expand_split_stack_prologue): Likewise. + * config/s390/s390.md (UNSPEC_GET_TP): New UNSPEC. + (*get_tp_31): New 31-bit splitter for UNSPEC_GET_TP. + (*get_tp_64): New 64-bit splitter for UNSPEC_GET_TP. + (get_thread_pointer): Use UNSPEC_GET_TP, use + parameterized name. + 2019-10-24 Richard Biener * tree-vect-slp.c (vect_analyze_slp): When reduction group diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c index 9fed7d3b99f..151b80da0b3 100644 --- a/gcc/config/s390/s390.c +++ b/gcc/config/s390/s390.c @@ -5106,7 +5106,8 @@ s390_get_thread_pointer (void) { rtx tp = gen_reg_rtx (Pmode); - emit_move_insn (tp, gen_rtx_REG (Pmode, TP_REGNUM)); + emit_insn (gen_get_thread_pointer (Pmode, tp)); + mark_reg_pointer (tp, BITS_PER_WORD); return tp; @@ -11711,7 +11712,7 @@ s390_expand_split_stack_prologue (void) /* Get thread pointer. r1 is the only register we can always destroy - r0 could contain a static chain (and cannot be used to address memory anyway), r2-r6 can contain parameters, and r6-r15 are callee-saved. */ - emit_move_insn (r1, gen_rtx_REG (Pmode, TP_REGNUM)); + emit_insn (gen_get_thread_pointer (Pmode, r1)); /* Aim at __private_ss. */ guard = gen_rtx_MEM (Pmode, plus_constant (Pmode, r1, psso)); diff --git a/gcc/config/s390/s390.md b/gcc/config/s390/s390.md index 1e6439d5fd6..e3881d07f2b 100644 --- a/gcc/config/s390/s390.md +++ b/gcc/config/s390/s390.md @@ -105,6 +105,7 @@ ; TLS support UNSPEC_TLSLDM_NTPOFF UNSPEC_TLS_LOAD + UNSPEC_GET_TP ; String Functions UNSPEC_SRST @@ -1860,23 +1861,35 @@ *,*,yes") ]) -; Splitters for loading/storing TLS pointers from/to %a0:DI. -; Do this only during split2, which runs after reload. At the point when split1 -; runs, some of %a0:DI occurrences might be nested inside other rtxes and thus -; not matched. As a result, only some occurrences will be split, which will -; prevent CSE. At the point when split2 runs, reload will have ensured that no -; nested references exist. +; Splitters for loading TLS pointer from UNSPEC_GET_TP. +; UNSPEC_GET_TP is used instead of %a0:P, since the latter is a hard register, +; and those are not handled by Partial Redundancy Elimination (gcse.c), which +; results in generation of redundant thread pointer loads. -(define_split - [(set (match_operand:DI 0 "register_operand" "") - (match_operand:DI 1 "register_operand" ""))] - "TARGET_ZARCH && ACCESS_REG_P (operands[1]) && reload_completed" +(define_insn_and_split "*get_tp_31" + [(set (match_operand:SI 0 "register_operand" "=r") + (unspec:SI [(match_operand:SI 1 "register_operand" "t")] + UNSPEC_GET_TP))] + "" + "#" + "&& reload_completed" + [(set (match_dup 0) (match_dup 1))]) + +(define_insn_and_split "*get_tp_64" + [(set (match_operand:DI 0 "register_operand" "=r") + (unspec:DI [(match_operand:DI 1 "register_operand" "t")] + UNSPEC_GET_TP))] + "TARGET_ZARCH" + "#" + "&& reload_completed" [(set (match_dup 2) (match_dup 3)) (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32))) (set (strict_low_part (match_dup 2)) (match_dup 4))] "operands[2] = gen_lowpart (SImode, operands[0]); s390_split_access_reg (operands[1], &operands[4], &operands[3]);") +; Splitters for storing TLS pointer to %a0:DI. + (define_split [(set (match_operand:DI 0 "register_operand" "") (match_operand:DI 1 "register_operand" ""))] @@ -10520,8 +10533,9 @@ ;;- Thread-local storage support. ;; -(define_expand "get_thread_pointer" - [(set (match_operand:P 0 "nonimmediate_operand" "") (reg:P TP_REGNUM))] +(define_expand "@get_thread_pointer" + [(set (match_operand:P 0 "nonimmediate_operand" "") + (unspec:P [(reg:P TP_REGNUM)] UNSPEC_GET_TP))] "" "") diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a752086d4cc..337002bf3e5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-10-24 Ilya Leoshkevich + + * gcc.target/s390/load-thread-pointer-once-2.c: New test. + 2019-10-24 Richard Biener * gcc.dg/vect/slp-reduc-9.c: New testcase. diff --git a/gcc/testsuite/gcc.target/s390/load-thread-pointer-once-2.c b/gcc/testsuite/gcc.target/s390/load-thread-pointer-once-2.c new file mode 100644 index 00000000000..36b1ed8800f --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/load-thread-pointer-once-2.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O3" } */ + +extern void c(void *); + +void a(void) +{ + void *b = __builtin_thread_pointer(); + if (b) + c(b); +} + +/* { dg-final { scan-assembler-times {\n\tear\t} 2 { target { lp64 } } } } */ +/* { dg-final { scan-assembler-times {\n\tear\t} 1 { target { ! lp64 } } } } */