public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/52848] New: [x32] *load_tp_x32 in i386.md isn't necessary
@ 2012-04-03 18:13 hjl.tools at gmail dot com
  2021-08-30  2:06 ` [Bug target/52848] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: hjl.tools at gmail dot com @ 2012-04-03 18:13 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52848

             Bug #: 52848
           Summary: [x32] *load_tp_x32 in i386.md isn't necessary
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: hjl.tools@gmail.com
            Target: x32


Segment register %fs is used as thread pointer for x32 in 64bit hardware mode.
For a memory operand "%fs:address", its effective address is the base address
of %fs + address.  The base address of %fs are hidden and "mov %fs, %ax" only
accesses the visible part of %fs, which is the 16bit segment selector.

In x32, UNSPEC_TP refers to the base address of %fs.  To access the
base address of %fs, a system call is provided:

    int arch_prctl(int code, unsigned long long addr);
    int arch_prctl(int code, unsigned long long *addr);

       ARCH_SET_FS
              Set the 64-bit base for the FS register to addr.

       ARCH_GET_FS
              Return the 64-bit base value for the FS register of the
          current thread in the unsigned long pointed to by addr.

We must use arch_prctl to update the base address of %fs,  To read
the base address of %fs, OS arranges that the base address of %fs points
to a struct:

typedef struct
{
  void *tcb;        /* Pointer to the TCB.  Not necessarily the
               thread descriptor used by libpthread.  */
  ...
}

and sets up "tcb" == the base address of %fs so that the address of "%fs:0"
is the address of the tcb field.  For x32, the base address of %fs is
between 0 and 0xffffffff.  We can use

"mov{l}\t{%%fs:0, %k0|%k0, DWORD PTR fs:0}"

to move the base address of %fs into %r32 and %r64 directly.  In case
of %r32, we are loading "tcb", which is a 32bit memory.  For %r64, we
are loading "tcb" and zero-extend it to 64bit.  We can use

;; Load and add the thread base pointer from %<tp_seg>:0.
(define_insn "*load_tp_x32_<mode>"
  [(set (match_operand:SWI48x 0 "register_operand" "=r") 
        (unspec:SWI48x [(const_int 0)] UNSPEC_TP))]
  "TARGET_X32"
  "mov{l}\t{%%fs:0, %k0|%k0, DWORD PTR fs:0}"
  [(set_attr "type" "imov")
   (set_attr "modrm" "0")
   (set_attr "length" "7")
   (set_attr "memory" "load")
   (set_attr "imm_disp" "false")])

instead of

;; Load and add the thread base pointer from %<tp_seg>:0.
(define_insn "*load_tp_x32"
  [(set (match_operand:SI 0 "register_operand" "=r") 
        (unspec:SI [(const_int 0)] UNSPEC_TP))]
  "TARGET_X32"
  "mov{l}\t{%%fs:0, %0|%0, DWORD PTR fs:0}"
  [(set_attr "type" "imov")
   (set_attr "modrm" "0")
   (set_attr "length" "7")
   (set_attr "memory" "load")
   (set_attr "imm_disp" "false")])

(define_insn "*load_tp_x32_zext"
  [(set (match_operand:DI 0 "register_operand" "=r")
        (zero_extend:DI (unspec:SI [(const_int 0)] UNSPEC_TP)))]
  "TARGET_X32"
  "mov{l}\t{%%fs:0, %k0|%k0, DWORD PTR fs:0}"
  [(set_attr "type" "imov")
   (set_attr "modrm" "0")
   (set_attr "length" "7")
   (set_attr "memory" "load")
   (set_attr "imm_disp" "false")])


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug target/52848] [x32] *load_tp_x32 in i386.md isn't necessary
  2012-04-03 18:13 [Bug target/52848] New: [x32] *load_tp_x32 in i386.md isn't necessary hjl.tools at gmail dot com
@ 2021-08-30  2:06 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-30  2:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52848

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think this was fixed with r8-2518.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-30  2:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-03 18:13 [Bug target/52848] New: [x32] *load_tp_x32 in i386.md isn't necessary hjl.tools at gmail dot com
2021-08-30  2:06 ` [Bug target/52848] " pinskia at gcc dot gnu.org

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).