https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87849
Bug ID: 87849 Summary: Missed optimization: useless for-loop must be eliminated Product: gcc Version: tree-ssa Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: zamazan4ik at tut dot by Target Milestone: --- gcc(trunk) with -O3 -std=c++17 for this code: #include <vector> #include <algorithm> int foo(std::vector<int> v) { int l = v[0]; for(const auto& x : v) { l = std::min(l, x); } for(const auto& x : v) { l = std::max(l, x); } return l; } gcc doesn't eliminate first loop, but gcc can, because first loop has no effect in this function.