public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/26674]  New: missed optimization / 128-bit arithmetic.
@ 2006-03-14 12:07 pluto at agmk dot net
  2006-03-14 13:25 ` [Bug target/26674] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: pluto at agmk dot net @ 2006-03-14 12:07 UTC (permalink / raw)
  To: gcc-bugs

__uint128_t sqr_1(__uint64_t x)
{
    return (x * (__uint128_t)x);
}

gcc-4.1.1-20060308 produces an ugly code:

sqr_1:  xorl    %edx, %edx      # D.1810
        movq    %rdi, %rax      # x, D.1810
        movq    %rdx, %rcx      #, tmp62
        imulq   %rdi, %rcx      # D.1810, tmp62
        mulq    %rdi    # D.1810
        addq    %rcx, %rcx      # tmp62
        addq    %rdx, %rcx      #, tmp62
        movq    %rcx, %rdx      # tmp62,
        ret

the optimal solution is:

        movq    %rdi, %rax
        mulq    %rax        ; or mulq %rdi
        ret


__uint128_t sqr_2(__uint64_t x)
{
    union {
        __uint128_t v;
        struct {
            __uint64_t lo;
            __uint64_t hi;
        } q;
    } r;
    asm volatile("mulq %%rax" : "=d" (r.q.hi), "=a" (r.q.lo) : "a" (x));
    return r.v;
}

sqr_2 gives better code but still unoptimal :/

sqr_2:  movq    %rdi, %rax      # x, x
#APP
        mulq %rax
#NO_APP
        movq    %rdx, -16(%rsp) # tmp60, r.q.hi
        movq    %rax, -24(%rsp) # tmp61, r.q.lo
        movq    -16(%rsp), %rdx # r.v, r.v
        movq    -24(%rsp), %rax # r.v, r.v
        ret


-- 
           Summary: missed optimization / 128-bit arithmetic.
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pluto at agmk dot net
 GCC build triplet: x86-64-linux
  GCC host triplet: x86-64-linux
GCC target triplet: x86-64-linux


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


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

* [Bug target/26674] missed optimization / 128-bit arithmetic.
  2006-03-14 12:07 [Bug other/26674] New: missed optimization / 128-bit arithmetic pluto at agmk dot net
@ 2006-03-14 13:25 ` pinskia at gcc dot gnu dot org
  2006-03-14 13:58 ` rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-14 13:25 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
          Component|other                       |target


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


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

* [Bug target/26674] missed optimization / 128-bit arithmetic.
  2006-03-14 12:07 [Bug other/26674] New: missed optimization / 128-bit arithmetic pluto at agmk dot net
  2006-03-14 13:25 ` [Bug target/26674] " pinskia at gcc dot gnu dot org
@ 2006-03-14 13:58 ` rguenth at gcc dot gnu dot org
  2006-03-14 14:00 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-03-14 13:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2006-03-14 13:58 -------
Confirmed.  The asm matches what we get from expand unfortunately.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-03-14 13:58:26
               date|                            |


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


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

* [Bug target/26674] missed optimization / 128-bit arithmetic.
  2006-03-14 12:07 [Bug other/26674] New: missed optimization / 128-bit arithmetic pluto at agmk dot net
  2006-03-14 13:25 ` [Bug target/26674] " pinskia at gcc dot gnu dot org
  2006-03-14 13:58 ` rguenth at gcc dot gnu dot org
@ 2006-03-14 14:00 ` rguenth at gcc dot gnu dot org
  2006-10-22 17:44 ` pluto at agmk dot net
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-03-14 14:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2006-03-14 14:00 -------
Testcase:

typedef int __int128 __attribute__((mode(TI)));

__int128 foo(long x)
{
  return x*(__int128)x;
}


-- 


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


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

* [Bug target/26674] missed optimization / 128-bit arithmetic.
  2006-03-14 12:07 [Bug other/26674] New: missed optimization / 128-bit arithmetic pluto at agmk dot net
                   ` (2 preceding siblings ...)
  2006-03-14 14:00 ` rguenth at gcc dot gnu dot org
@ 2006-10-22 17:44 ` pluto at agmk dot net
  2008-02-20  9:48 ` pluto at agmk dot net
  2008-04-21  7:26 ` ubizjak at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: pluto at agmk dot net @ 2006-10-22 17:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pluto at agmk dot net  2006-10-22 17:44 -------
recent 4.2 produces worse %rcx setup code.

previously:

xorl    %edx, %edx
movq    %rdx, %rcx

now:

movq    %rdi, %rax
sarq    $63, %rax
movq    %rax, %rcx


-- 


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


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

* [Bug target/26674] missed optimization / 128-bit arithmetic.
  2006-03-14 12:07 [Bug other/26674] New: missed optimization / 128-bit arithmetic pluto at agmk dot net
                   ` (3 preceding siblings ...)
  2006-10-22 17:44 ` pluto at agmk dot net
@ 2008-02-20  9:48 ` pluto at agmk dot net
  2008-04-21  7:26 ` ubizjak at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: pluto at agmk dot net @ 2008-02-20  9:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pluto at agmk dot net  2008-02-20 09:48 -------
4.2.3 produces:

sqr_1:  xorl    %edx, %edx      # 45    *movdi_xor_rex64        [length = 2]
        movq    %rdi, %rax      # 11    *movdi_1_rex64/2        [length = 6]
        movq    %rdx, %rcx      # 40    *movdi_1_rex64/2        [length = 6]
        imulq   %rdi, %rcx      # 15    *muldi3_1_rex64/3       [length = 4]
        mulq    %rdi    # 18    *umulditi3_insn [length = 3]
        addq    %rcx, %rcx      # 17    *ashldi3_1_rex64/1      [length = 4]
        addq    %rdx, %rcx      # 19    *adddi_1_rex64/1        [length = 3]
        movq    %rcx, %rdx      # 20    *movdi_1_rex64/2        [length = 6]
        ret     # 43    return_internal [length = 1]

4.3-svn:

sqr_1:  movq    %rdi, %rax      # 35    *movdi_1_rex64/2        [length = 6]
        mulq    %rdi    # 13    *umulditi3_insn [length = 3]
        ret     # 41    return_internal [length = 1]


-- 

pluto at agmk dot net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|4.1.2 4.2.0                 |4.1.2 4.2.3
      Known to work|                            |4.3.0


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


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

* [Bug target/26674] missed optimization / 128-bit arithmetic.
  2006-03-14 12:07 [Bug other/26674] New: missed optimization / 128-bit arithmetic pluto at agmk dot net
                   ` (4 preceding siblings ...)
  2008-02-20  9:48 ` pluto at agmk dot net
@ 2008-04-21  7:26 ` ubizjak at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: ubizjak at gmail dot com @ 2008-04-21  7:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from ubizjak at gmail dot com  2008-04-21 07:26 -------
Not a regression, so the fix won't be backported on release branches.


-- 

ubizjak at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.3.0


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


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

end of thread, other threads:[~2008-04-21  7:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-14 12:07 [Bug other/26674] New: missed optimization / 128-bit arithmetic pluto at agmk dot net
2006-03-14 13:25 ` [Bug target/26674] " pinskia at gcc dot gnu dot org
2006-03-14 13:58 ` rguenth at gcc dot gnu dot org
2006-03-14 14:00 ` rguenth at gcc dot gnu dot org
2006-10-22 17:44 ` pluto at agmk dot net
2008-02-20  9:48 ` pluto at agmk dot net
2008-04-21  7:26 ` ubizjak at gmail dot com

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