public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Uros Bizjak <ubizjak@gmail.com>
Cc: gcc-patches@gcc.gnu.org, Richard Henderson <rth@redhat.com>
Subject: Re: PATCH: Properly generate X32 IE sequence
Date: Mon, 19 Mar 2012 16:20:00 -0000	[thread overview]
Message-ID: <CAMe9rOpYK6E8tEtdp9gtoLiXa69m9cvfPCJk-6N7onokPqYZvw@mail.gmail.com> (raw)
In-Reply-To: <CAMe9rOrv=C9ukqJqF7939n8n4bZ44TONcDBz3JQg+ysgD=J9iw@mail.gmail.com>

On Mon, Mar 19, 2012 at 8:54 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Mon, Mar 19, 2012 at 8:51 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Sun, Mar 18, 2012 at 1:55 PM, Uros Bizjak <ubizjak@gmail.com> wrote:
>>> On Sun, Mar 18, 2012 at 5:01 PM, Uros Bizjak <ubizjak@gmail.com> wrote:
>>>
>>>>> I am testing this patch.  OK for trunk if it passes all tests?
>>>>
>>>> No, force_reg will generate a pseudo, so this conversion is valid only
>>>> for !can_create_pseudo ().
>>>>
>>>> At least for *tls_initial_exec_x32_store, you will need a temporary to
>>>> split the pattern after reload.
>>
>> Here is the updated patch to add can_create_pseudo.  I also changed
>> tls_initial_exec_x32 to take an input register operand as thread pointer.
>>
>>> Please try attached patch. It simply throws away all recent
>>> complications w.r.t. to thread pointer and always handles TP in
>>> DImode.
>>>
>>> The testcase:
>>>
>>> --cut here--
>>> __thread int foo __attribute__ ((tls_model ("initial-exec")));
>>>
>>> void bar (int x)
>>> {
>>>  foo = x;
>>> }
>>>
>>> int baz (void)
>>> {
>>>  return foo;
>>> }
>>> --cut here--
>>>
>>> Now compiles to:
>>>
>>> bar:
>>>        movq    foo@gottpoff(%rip), %rax
>>>        movl    %edi, %fs:(%rax)
>>>        ret
>>>
>>> baz:
>>>        movq    foo@gottpoff(%rip), %rax
>>>        movl    %fs:(%rax), %eax
>>>        ret
>>>
>>> In effect, this always generates %fs(%rDI) and emits REX prefix before
>>> mov/add to satisfy brain-dead linkers.
>>>
>>> The patch is bootstrapping now on x86_64-pc-linux-gnu.
>>>
>>
>> For
>>
>> --
>> extern __thread char c;
>> extern char y;
>> void
>> ie (void)
>> {
>>  y = c;
>> }
>> --
>>
>> Your patch generates:
>>
>>        movl    %fs:0, %eax
>>        movq    c@gottpoff(%rip), %rdx
>>        movzbl  (%rax,%rdx), %edx
>>        movb    %dl, y(%rip)
>>        ret
>>
>> It can be optimized to:
>>
>>        movq    c@gottpoff(%rip), %rax
>>        movzbl  %fs:(%rax), %eax
>>        movb    %al, y(%rip)
>>        ret
>>
>
> Combine failed:
>
> (set (reg:QI 63 [ c ])
>    (mem/c:QI (plus:DI (zero_extend:DI (unspec:SI [
>                        (const_int 0 [0])
>                    ] UNSPEC_TP))
>            (mem/u/c:DI (const:DI (unspec:DI [
>                            (symbol_ref:SI ("c") [flags 0x60]
> <var_decl 0x7ffff19b8140 c>)
>                        ] UNSPEC_GOTNTPOFF)) [2 S8 A8])) [0 c+0 S1 A8]))
>
>

Wrong testcase.  IT should be

--
extern __thread char c;
extern __thread short w;
extern char y;
extern short i;
void
ie (void)
{
  y = c;
  i = w;
}
---

I got

	movl	%fs:0, %eax	
	movq	c@gottpoff(%rip), %rdx	
	movzbl	(%rax,%rdx), %edx	
	movb	%dl, y(%rip)	
	movq	w@gottpoff(%rip), %rdx	
	movzwl	(%rax,%rdx), %eax	
	movw	%ax, i(%rip)	
	ret	

It can be

	movq	c@gottpoff(%rip), %rax	
	movzbl	%fs:(%rax), %eax	
	movb	%al, y(%rip)	
	movq	w@gottpoff(%rip), %rax	
	movzwl	%fs:(%rax), %eax	
	movw	%ax, i(%rip)	
	ret	



-- 
H.J.

  reply	other threads:[~2012-03-19 16:20 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-09 22:26 H.J. Lu
2012-03-10 13:10 ` Uros Bizjak
2012-03-10 18:50   ` H.J. Lu
2012-03-11 17:12     ` H.J. Lu
2012-03-11 17:55       ` Uros Bizjak
2012-03-11 18:16         ` H.J. Lu
2012-03-11 18:21           ` Uros Bizjak
2012-03-11 21:25             ` H.J. Lu
2012-03-12 19:39               ` Uros Bizjak
2012-03-12 22:35                 ` H.J. Lu
2012-03-13  1:21                   ` H.J. Lu
2012-03-13  7:11                     ` Uros Bizjak
2012-03-13 10:37                       ` Uros Bizjak
2012-03-13 15:47                         ` H.J. Lu
2012-03-17 17:53                         ` H.J. Lu
2012-03-17 18:10       ` Uros Bizjak
2012-03-17 18:19         ` H.J. Lu
2012-03-17 18:21           ` Uros Bizjak
2012-03-17 21:50             ` H.J. Lu
2012-03-18 16:02               ` Uros Bizjak
2012-03-18 20:55                 ` Uros Bizjak
2012-03-19 15:51                   ` H.J. Lu
2012-03-19 15:54                     ` H.J. Lu
2012-03-19 16:20                       ` H.J. Lu [this message]
2012-03-19 16:35                         ` H.J. Lu
2012-03-19 16:38                           ` Uros Bizjak
2012-03-19 16:47                             ` H.J. Lu
2012-03-19 16:49                               ` Uros Bizjak
2012-03-19 16:56                                 ` H.J. Lu
2012-03-19 17:02                                   ` Uros Bizjak
2012-03-19 17:30                                     ` Uros Bizjak
2012-03-19 17:50                                       ` H.J. Lu
2012-03-19 19:14                                         ` Uros Bizjak
2012-03-20  9:35                                           ` Paolo Bonzini
2012-03-19 16:47                         ` Uros Bizjak
2012-03-20  8:52                   ` Eric Botcazou
2012-03-20  8:59                     ` Jakub Jelinek
2012-03-20 11:20                       ` Jakub Jelinek
2012-03-20 15:52                         ` H.J. Lu
2012-03-20 17:55                           ` Uros Bizjak
2012-03-20 18:27                             ` H.J. Lu
2012-03-20 18:44                               ` Uros Bizjak
2012-03-20 19:26                                 ` H.J. Lu

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=CAMe9rOpYK6E8tEtdp9gtoLiXa69m9cvfPCJk-6N7onokPqYZvw@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rth@redhat.com \
    --cc=ubizjak@gmail.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).