public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/43644]  New: __uint128_t missed optimizations.
@ 2010-04-04 23:58 svfuerst at gmail dot com
  2010-04-05 10:03 ` [Bug target/43644] " rguenth at gcc dot gnu dot org
  0 siblings, 1 reply; 6+ messages in thread
From: svfuerst at gmail dot com @ 2010-04-04 23:58 UTC (permalink / raw)
  To: gcc-bugs

__uint128_t foo1(__uint128_t x, __uint128_t y)
{
        return x + y;
}

   0x0000000000000520 <+0>:     mov    %rdx,%rax
   0x0000000000000523 <+3>:     mov    %rcx,%rdx
   0x0000000000000526 <+6>:     push   %rbx
   0x0000000000000527 <+7>:     add    %rdi,%rax
   0x000000000000052a <+10>:    adc    %rsi,%rdx
   0x000000000000052d <+13>:    pop    %rbx
   0x000000000000052e <+14>:    retq

%rbx isn't used, yet is saved and restored.

__uint128_t foo2(__uint128_t x, unsigned long long y)
{
        return x + y;
}
   0x0000000000000550 <+0>:     mov    %rdx,%rax
   0x0000000000000553 <+3>:     push   %rbx
   0x0000000000000554 <+4>:     xor    %edx,%edx
   0x0000000000000556 <+6>:     mov    %rsi,%rbx
   0x0000000000000559 <+9>:     add    %rdi,%rax
   0x000000000000055c <+12>:    adc    %rbx,%rdx
   0x000000000000055f <+15>:    pop    %rbx
   0x0000000000000560 <+16>:    retq

%rbx is used, but doesn't need to be. %rcx can be used instead, saving a
push-pop pair.

__uint128_t foo3(unsigned long long x, __uint128_t y)
{
        return x + y;
}

   0x0000000000000580 <+0>:     mov    %rdi,%rax
   0x0000000000000583 <+3>:     push   %rbx
   0x0000000000000584 <+4>:     mov    %rdx,%rbx
   0x0000000000000587 <+7>:     xor    %edx,%edx
   0x0000000000000589 <+9>:     add    %rsi,%rax
   0x000000000000058c <+12>:    adc    %rbx,%rdx
   0x000000000000058f <+15>:    pop    %rbx
   0x0000000000000590 <+16>:    retq

Similar problems as with the previous two functions, with the addition of the
fact that %rdx can now be used in-situ as an output, avoiding one of the mov
instructions.  i.e. the function could be optimized to be:

mov    %rdi,%rax
xor    %ecx,%ecx
add    %rsi,%rax
adc    %rcx,%rdx
retq


-- 
           Summary: __uint128_t missed optimizations.
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: svfuerst at gmail dot com
 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=43644


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

end of thread, other threads:[~2024-04-26 12:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-43644-4@http.gcc.gnu.org/bugzilla/>
2023-05-07  6:57 ` [Bug target/43644] __uint128_t missed optimizations cvs-commit at gcc dot gnu.org
2023-07-07 19:41 ` cvs-commit at gcc dot gnu.org
2023-08-01  8:21 ` jbeulich at suse dot com
2023-12-31 21:39 ` cvs-commit at gcc dot gnu.org
2024-04-26 12:59 ` roger at nextmovesoftware dot com
2010-04-04 23:58 [Bug c/43644] New: " svfuerst at gmail dot com
2010-04-05 10:03 ` [Bug target/43644] " rguenth at gcc dot gnu dot 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).