From: Ilya Leoshkevich <iii@linux.ibm.com>
To: gcc-patches@gcc.gnu.org, krebbel@linux.ibm.com
Cc: uweigand@de.ibm.com, stli@linux.ibm.com,
Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PATCH] S/390: Use UNSPEC_GET_TP for thread pointer loads
Date: Wed, 23 Oct 2019 11:06:00 -0000 [thread overview]
Message-ID: <20191023110235.11457-1-iii@linux.ibm.com> (raw)
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
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 } } } } */
--
2.23.0
next reply other threads:[~2019-10-23 11:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-23 11:06 Ilya Leoshkevich [this message]
2019-10-24 7:11 ` Andreas Krebbel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191023110235.11457-1-iii@linux.ibm.com \
--to=iii@linux.ibm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=krebbel@linux.ibm.com \
--cc=stli@linux.ibm.com \
--cc=uweigand@de.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).