[Bug c++/87849] Missed optimization: useless for-loop must be eliminated
zamazan4ik at tut dot by
gcc-bugzilla@gcc.gnu.org
Thu Nov 1 13:18:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87849
--- Comment #1 from Alexander Zaitsev <zamazan4ik at tut dot by> ---
Same for code without using STL algorithms and containers:
int min(int a, int b)
{
return a < b ? a : b;
}
int max(int a, int b)
{
return a > b ? a : b;
}
int foo(int* v, int size) {
int l = v[0];
for(int i=0; i < size; ++i)
{
l = min(l, v[i]);
}
for(int i=0; i < size; ++i)
{
l = max(l, v[i]);
}
return l;
}
Result of function doesn't depend on the result of first loop and it can be
eliminated.
More information about the Gcc-bugs
mailing list