public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/109746] New: Fails removing redundant comparison in for loop over multiple variables, unless members of struct
@ 2023-05-05 10:10 magnus.hegdahl at gmail dot com
2023-05-05 12:21 ` [Bug tree-optimization/109746] " rguenth at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: magnus.hegdahl at gmail dot com @ 2023-05-05 10:10 UTC (permalink / raw)
To: gcc-bugs
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();
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug tree-optimization/109746] Fails removing redundant comparison in for loop over multiple variables, unless members of struct
2023-05-05 10:10 [Bug tree-optimization/109746] New: Fails removing redundant comparison in for loop over multiple variables, unless members of struct magnus.hegdahl at gmail dot com
@ 2023-05-05 12:21 ` rguenth at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-05-05 12:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109746
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Probably some pass ordering issue.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-05-05 12:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-05 10:10 [Bug tree-optimization/109746] New: Fails removing redundant comparison in for loop over multiple variables, unless members of struct magnus.hegdahl at gmail dot com
2023-05-05 12:21 ` [Bug tree-optimization/109746] " rguenth 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).