On Wed, Sep 9, 2020 at 1:17 AM Hongtao Liu <crazy...@gmail.com> wrote:
>
> On Wed, Sep 9, 2020 at 2:35 PM Jakub Jelinek <ja...@redhat.com> wrote:
> >
> > On Wed, Sep 09, 2020 at 10:30:46AM +0800, Hongtao Liu wrote:
> > > From 400418fadce46e7db7bd37be45ef5ff5beb08d19 Mon Sep 17 00:00:00 2001
> > > From: liuhongt <hongtao....@intel.com>
> > > Date: Tue, 8 Sep 2020 15:44:58 +0800
> > > Subject: [PATCH] Implement __builtin_thread_pointer for x86 TLS.
> > >
> > > gcc/ChangeLog:
> > >       PR target/96955
> > >       * config/i386/i386.md (get_thread_pointer<mode>): New
> > >       expander.
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > >       * gcc.target/i386/builtin_thread_pointer.c: New test.
> > > ---
> > >  gcc/config/i386/i386.md                       | 10 +++++++
> > >  .../gcc.target/i386/builtin_thread_pointer.c  | 28 +++++++++++++++++++
> > >  2 files changed, 38 insertions(+)
> > >  create mode 100644 gcc/testsuite/gcc.target/i386/builtin_thread_pointer.c
> > >
> > > diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
> > > index 446793b78db..2f6eb0a7b98 100644
> > > --- a/gcc/config/i386/i386.md
> > > +++ b/gcc/config/i386/i386.md
> > > @@ -15433,6 +15433,16 @@ (define_insn_and_split 
> > > "*tls_local_dynamic_32_once"
> > >        (clobber (reg:CC FLAGS_REG))])])
> > >
> > >  ;; Load and add the thread base pointer from %<tp_seg>:0.
> > > +(define_expand "get_thread_pointer<mode>"
> > > +  [(set (match_operand:PTR 0 "register_operand")
> > > +     (unspec:PTR [(const_int 0)] UNSPEC_TP))]
> > > +  ""
> > > +{
> > > +  /* targetm is not existed in the scope of condition.  */
> >
> > Reword as "targetm is not visible in the scope of the condition."
> > In fact, even if it was, it wouldn't help, because 
> > expand_builtin_thread_pointer
> > assumes that if the expander exists, then it will work and emit some code
> > and emits the error only if the expander doesn't exist.
> >
> > Ok for trunk with that change, thanks.
> >
>
> Thanks for the review.
>

I am checking in this for x32.

-- 
H.J.
From 64a1b56db4793833ff8d97c7fe1b200689250764 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.to...@gmail.com>
Date: Wed, 9 Sep 2020 10:29:47 -0700
Subject: [PATCH] x32: Update gcc.target/i386/builtin_thread_pointer.c

Update gcc.target/i386/builtin_thread_pointer.c for x32.  For

int
foo3 (int i)
{
  int* p = (int*) __builtin_thread_pointer ();
  return p[i];
}

we can't generate:

	movl	%fs:0(,%edi,4), %eax
	ret

for x32 since the address of %fs:0(,%edi,4) is %fs + zero-extended to 64
bits of 0(,%edi,4).  Instead we generate

	movl	%fs:0, %eax
	movl	(%eax,%edi,4), %eax

	PR target/96955
	* gcc.target/i386/builtin_thread_pointer.c: Update scan-assembler
	for x32
---
 gcc/testsuite/gcc.target/i386/builtin_thread_pointer.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/i386/builtin_thread_pointer.c b/gcc/testsuite/gcc.target/i386/builtin_thread_pointer.c
index dce31488117..16a7ca49b99 100644
--- a/gcc/testsuite/gcc.target/i386/builtin_thread_pointer.c
+++ b/gcc/testsuite/gcc.target/i386/builtin_thread_pointer.c
@@ -25,4 +25,6 @@ foo3 (int i)
   return p[i];
 }
 
-/* { dg-final { scan-assembler "movl\[ \t\]*%\[fg\]s:0\\(,%\[a-z0-9\]*,4\\), %eax" } }  */
+/* { dg-final { scan-assembler "movl\[ \t\]*%\[fg\]s:0\\(,%\[a-z0-9\]*,4\\), %eax" { target { ! x32 } } } }  */
+/* { dg-final { scan-assembler-not "movl\[ \t\]*%fs:0\\(,%\[a-z0-9\]*,4\\), %eax" { target x32 } } }  */
+/* { dg-final { scan-assembler "movl\[ \t\]*\\(%eax,%edi,4\\), %eax" { target x32 } } }  */
-- 
2.26.2

Reply via email to