diff mbox series

S/390: Use UNSPEC_GET_TP for thread pointer loads

Message ID 20191023110235.11457-1-iii@linux.ibm.com
State New
Headers show
Series S/390: Use UNSPEC_GET_TP for thread pointer loads | expand

Commit Message

Ilya Leoshkevich Oct. 23, 2019, 11:02 a.m. UTC
Boostrapped and regtested on s390x-redhat-linux.

gcc/ChangeLog:

2019-10-21  Ilya Leoshkevich  <iii@linux.ibm.com>

	* 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<mode>): Use UNSPEC_GET_TP, use
	parameterized name.

gcc/testsuite/ChangeLog:

2019-10-21  Ilya Leoshkevich  <iii@linux.ibm.com>

	* gcc.target/s390/load-thread-pointer-once-2.c: New test.
---
 gcc/config/s390/s390.c                        |  5 ++-
 gcc/config/s390/s390.md                       | 38 +++++++++++++------
 .../s390/load-thread-pointer-once-2.c         | 14 +++++++
 3 files changed, 43 insertions(+), 14 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/s390/load-thread-pointer-once-2.c

Comments

Andreas Krebbel Oct. 24, 2019, 6:56 a.m. UTC | #1
On 23.10.19 13:02, Ilya Leoshkevich wrote:
> Boostrapped and regtested on s390x-redhat-linux.
> 
> gcc/ChangeLog:
> 
> 2019-10-21  Ilya Leoshkevich  <iii@linux.ibm.com>
> 
> 	* 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<mode>): Use UNSPEC_GET_TP, use
> 	parameterized name.
> 
> gcc/testsuite/ChangeLog:
> 
> 2019-10-21  Ilya Leoshkevich  <iii@linux.ibm.com>
> 
> 	* gcc.target/s390/load-thread-pointer-once-2.c: New test.

Ok. Thanks!

Andreas
diff mbox series

Patch

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<mode>"
-  [(set (match_operand:P 0 "nonimmediate_operand" "") (reg:P TP_REGNUM))]
+(define_expand "@get_thread_pointer<mode>"
+  [(set (match_operand:P 0 "nonimmediate_operand" "")
+	(unspec:P [(reg:P TP_REGNUM)] UNSPEC_GET_TP))]
   ""
   "")
 
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 } } } } */