https://gcc.gnu.org/bugzilla/show_bug.cgi?id=73457
Bug ID: 73457
Summary: Missed optimizations: count_if on std::array of
constants.
Product: gcc
Version: 6.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: rureclonic at thraml dot com
Target Milestone: ---
First of all, given how simple this bug report is, I imagine it must be a
duplicate, but am not sure what to look for and didn't find anything very
relevant. Apologies therefore.
gcc: https://godbolt.org/g/kAhsRr
clang: https://godbolt.org/g/B3fsWi
It seems gcc is unable to fold the std::count_if over the std::array despite it
being constant-initialized, while clang optimizes the program away.
Adding constexpr does not change the output. Replacing std::array with an
initializer list makes gcc optimize everything: https://godbolt.org/g/chOqnZ