public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "andre.schackier at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/105137] New: Missed optimization 64-bit adds and shifts Date: Sat, 02 Apr 2022 14:01:18 +0000 [thread overview] Message-ID: <bug-105137-4@http.gcc.gnu.org/bugzilla/> (raw) 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
next reply other threads:[~2022-04-02 14:01 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-02 14:01 andre.schackier at gmail dot com [this message] 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
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=bug-105137-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /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: linkBe 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).