public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "vanyacpp at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/98709] New: gcc optimizes bitwise operations, but doesn't optimize logical ones Date: Sun, 17 Jan 2021 01:31:15 +0000 [thread overview] Message-ID: <bug-98709-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98709 Bug ID: 98709 Summary: gcc optimizes bitwise operations, but doesn't optimize logical ones Product: gcc Version: 10.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: vanyacpp at gmail dot com Target Milestone: --- GCC 10.2 produces very good code for this function noticing that both sides of conjuntion are the same: unsigned foo_bitwise(unsigned a, unsigned b) { return (~a ^ b) & ~(a ^ b); } foo_bitwise(unsigned int, unsigned int): xor edi, esi mov eax, edi not eax ret But when I write a similar function with logical operations it doesn't notice that: bool foo_logical(bool a, bool b) { return (!a ^ b) & !(a ^ b); } foo_logical(bool, bool): mov eax, esi xor eax, edi xor eax, 1 cmp dil, sil sete dl and eax, edx ret I believe that in a similar manner it can be optimized to something like this: foo_logical(bool, bool): xor edi, esi mov eax, edi xor eax, 1 ret
next reply other threads:[~2021-01-17 1:31 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-01-17 1:31 vanyacpp at gmail dot com [this message] 2021-01-17 17:34 ` [Bug middle-end/98709] " glisse at gcc dot gnu.org 2021-08-01 18:17 ` [Bug tree-optimization/98709] " pinskia at gcc dot gnu.org 2022-08-10 11:46 ` vanyacpp at gmail dot com 2022-10-22 2:13 ` pinskia 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-98709-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).