public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "kyrylo.bohdanenko at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/101240] New: [missed optimization] Transitivity of less-than and less-or-equal Date: Mon, 28 Jun 2021 12:03:52 +0000 [thread overview] Message-ID: <bug-101240-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101240 Bug ID: 101240 Summary: [missed optimization] Transitivity of less-than and less-or-equal Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: kyrylo.bohdanenko at gmail dot com Target Milestone: --- Consider the following C++ code #define ALWAYS_TRUE(x) do { if (x) __builtin_unreachable(); } while (false) int divide(int a, int b) { ALWAYS_TRUE(a == b); return a / b; } void test_array(unsigned (&arr)[3]) { ALWAYS_TRUE(a[0] < a[1] && a[1] < a[2]); return a[0] < a[2]; } The first function is optimiozed away: divide(int, int): mov eax, 1 ret While the second still does the comparison: test_array(unsigned int (&) [3]): mov eax, DWORD PTR [rdi+8] cmp DWORD PTR [rdi], eax setb al ret It would be nice if GCC could deduce that a < b && b < c --> a < c And optimize that second function (provided no other UB is involved)
next reply other threads:[~2021-06-28 12:03 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-06-28 12:03 kyrylo.bohdanenko at gmail dot com [this message] 2021-06-29 7:01 ` [Bug tree-optimization/101240] " rguenth at gcc dot gnu.org 2021-06-29 7:04 ` rguenth at gcc dot gnu.org 2021-11-05 21:31 ` amacleod at redhat dot com 2021-11-05 22:04 ` aldyh at gcc dot gnu.org 2023-07-13 18:27 ` 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-101240-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).