https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123291
Bug ID: 123291
Summary: missed optimization for summing 0...n-1 in a loop
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: uecker at gcc dot gnu.org
Target Milestone: ---
As seen on Matt Godbolt's blog Clang can optimize away the following loop. Not
sure where this is really needed, but I leave it here for reference.
https://xania.org/202512/24-cunning-clang
int sum_up_to(int value) {
int result = 0;
for (int x = 0; x < value; ++x) {
result += x;
}
return result;
}
https://aoco.compiler-explorer.com/z/xh8Edo8vM