public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/105137] New: Missed optimization 64-bit adds and shifts
@ 2022-04-02 14:01 andre.schackier at gmail dot com
  2022-11-28 20:03 ` [Bug middle-end/105137] " pinskia at gcc dot gnu.org
  2023-01-01 17:01 ` cvs-commit at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: andre.schackier at gmail dot com @ 2022-04-02 14:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105137
           Summary: Missed optimization 64-bit adds and shifts
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andre.schackier at gmail dot com
  Target Milestone: ---

Given the following source code [godbolt](https://godbolt.org/z/8KMMhefqY)

#include <stdint.h>

typedef __int128_t int128_t;
int64_t foo(int128_t a, int64_t b, int cond) {
    if (cond) {
        a += ((int128_t)b) << 64;
    }
    return a >> 64;
}

int64_t bar(int128_t a, int64_t b, int cond) {
    int64_t r = a >> 64;
    if (cond) {
        r += b;
    }
    return r;
}

Compiling with "-O3" we get:

foo:
        mov     rax, rsi
        mov     rsi, rdi
        mov     rdi, rax
        test    ecx, ecx
        je      .L2
        xor     r8d, r8d
        add     rsi, r8
        adc     rdi, rdx
.L2:
        mov     rax, rdi
        ret
bar:
        add     rdx, rsi
        mov     rax, rsi
        test    ecx, ecx
        cmovne  rax, rdx
        ret

Although both functions do the same, gcc implements worse code for foo.

Credits: This was entirely found by Trevor Spiteri reported at the llvm-project
here: https://github.com/llvm/llvm-project/issues/54718

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

end of thread, other threads:[~2023-01-01 17:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-02 14:01 [Bug middle-end/105137] New: Missed optimization 64-bit adds and shifts andre.schackier at gmail dot com
2022-11-28 20:03 ` [Bug middle-end/105137] " pinskia at gcc dot gnu.org
2023-01-01 17:01 ` cvs-commit 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).