public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "magnus.hegdahl at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109746] New: Fails removing redundant comparison in for loop over multiple variables, unless members of struct Date: Fri, 05 May 2023 10:10:40 +0000 [thread overview] Message-ID: <bug-109746-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109746 Bug ID: 109746 Summary: Fails removing redundant comparison in for loop over multiple variables, unless members of struct Product: gcc Version: 13.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: magnus.hegdahl at gmail dot com Target Milestone: --- Compiled with g++ (GCC) 13.1.1 20230429 on x86-64 Linux, with -O2 or higher. In the code below, the comparisons with i are redundant because j is increasing much faster. GCC manages to optimize this away when i and j are members of some struct, but not when they are just integers. struct S { unsigned x; }; unsigned f() { unsigned N = 1e9, x = 0; for (unsigned i = 3, j = 1; i < N && j < N; i += 2, j += 3) x ^= i * j; return x; } unsigned g() { unsigned N = 1e9, x = 0; for (S i {3}, j {1}; i.x < N && j.x < N; i.x += 2, j.x += 3) x ^= i.x * j.x; return x; } int main() { return f(); }
next reply other threads:[~2023-05-05 10:10 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-05 10:10 magnus.hegdahl at gmail dot com [this message] 2023-05-05 12:21 ` [Bug tree-optimization/109746] " rguenth 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-109746-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).