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. > + if (!targetm.have_tls) > + error ("%<__builtin_thread_pointer%> is not supported on this target"); > +}) > + Jakub