[Bug tree-optimization/58122] New: loops are not evaluated at compile time if loop count > 17
olegendo at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sun Aug 11 11:13:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58122
Bug ID: 58122
Summary: loops are not evaluated at compile time if loop count
> 17
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: olegendo at gcc dot gnu.org
This one was originally reported here:
http://gcc.gnu.org/ml/gcc-help/2013-08/msg00124.html
The original example was:
#include <stdio.h>
template <typename T>
inline T const& max (T const& a, T const& b)
{
return a < b ? b : a;
}
int main()
{
long long unsigned sum = 0;
for (int x = 1; x <= 100000000; x++)
sum += max (x, x + 1);
printf("%llu\n", sum);
}
It seems that GCC 4.7 was able to evaluate the loop at compile time and reduce
it to a constant value, but GCC 4.8 fails to do so.
I've also briefly checked with trunk rev 201282 and the problem seems to be
still there. Here is a reduced test case:
int test (void)
{
int sum = 0;
for (int x = 0; x < 100; x++)
sum += x;
return sum;
}
I've checked this with an SH cross compiler setup, but I don't think it
matters.
The loops do get eliminated if the number of loop iterations is max. 17, for
both the reduced example and the originally reported case.
More information about the Gcc-bugs
mailing list