https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78151
Bug ID: 78151 Summary: Fail to vectorize *min_element Product: gcc Version: 7.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: glisse at gcc dot gnu.org Target Milestone: --- (from a discussion in the comments of http://stackoverflow.com/a/40284138/1918193) #include <vector> #include <algorithm> int return_min(std::vector<int> &v) { return *std::min_element(v.begin(), v.end()); } Normally, min_element returns a position, which makes it hard to optimize. In this case, we notice quite nicely that only the value is needed and not the position. However, this only happens in PRE. We then wait until phiopt3 to recognize a MIN_EXPR. And that's too late for the vectorizer :-(