diff options
author | liuhongt <hongtao.liu@intel.com> | 2020-09-08 15:44:58 +0800 |
---|---|---|
committer | liuhongt <hongtao.liu@intel.com> | 2020-09-09 16:17:42 +0800 |
commit | e470d8af81d390df1166e9d9cf10b00c0692a495 (patch) | |
tree | 91061b4a38afd671e386381458015997ed723e0e /gcc | |
parent | 61c2d476a52bb108bd05d0226c5522bf0c4b24b5 (diff) | |
download | gcc-e470d8af81d390df1166e9d9cf10b00c0692a495.zip gcc-e470d8af81d390df1166e9d9cf10b00c0692a495.tar.gz gcc-e470d8af81d390df1166e9d9cf10b00c0692a495.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/config/i386/i386.md | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/builtin_thread_pointer.c | 28 |
2 files changed, 38 insertions, 0 deletions
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 446793b..93aae81 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -15433,6 +15433,16 @@ (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 visible in the scope of the condition. */ + if (!targetm.have_tls) + error ("%<__builtin_thread_pointer%> is not supported on this target"); +}) + (define_insn_and_split "*load_tp_<mode>" [(set (match_operand:PTR 0 "register_operand" "=r") (unspec:PTR [(const_int 0)] UNSPEC_TP))] diff --git a/gcc/testsuite/gcc.target/i386/builtin_thread_pointer.c b/gcc/testsuite/gcc.target/i386/builtin_thread_pointer.c new file mode 100644 index 0000000..dce3148 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/builtin_thread_pointer.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-mtls-direct-seg-refs -O2 -masm=att" } */ + +int* +foo1 () +{ + return (int*) __builtin_thread_pointer (); +} + +/* { dg-final { scan-assembler "mov\[lq\]\[ \t\]*%\[fg\]s:0, %\[re\]ax" } } */ + +int +foo2 () +{ + int* p = (int*) __builtin_thread_pointer (); + return p[4]; +} + +/* { dg-final { scan-assembler "movl\[ \t\]*%\[fg\]s:16, %eax" } } */ + +int +foo3 (int i) +{ + int* p = (int*) __builtin_thread_pointer (); + return p[i]; +} + +/* { dg-final { scan-assembler "movl\[ \t\]*%\[fg\]s:0\\(,%\[a-z0-9\]*,4\\), %eax" } } */ |