https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96252
Bug ID: 96252 Summary: mis-optimization where identical functions have very different codegen since gcc 10 Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: wjwray at gmail dot com Target Milestone: --- (Stumbled on this odd effect while examining codegen for operator<=>) The reduced sample compiles c++11 and up (std version likely irrelevant) with the different codegen occurring since GCC 10. Two identical functions: bool cmp_x(cmp l, cmp r) noexcept { return std::lexicographical_compare(begin(l),end(l) ,begin(r),end(r)); } bool cmp_y(cmp l, cmp r) noexcept { return std::lexicographical_compare(begin(l),end(l) ,begin(r),end(r)); } generate very different code for cmp = array<int,64> at -O2 and -O3. The first is looping, the second has much longer unrolled codegen. My benchmarks show 40% difference in runtime, quick-bench shows 30%. Compiler Explorer https://godbolt.org/z/97box6 Quick-bench 1.3x https://quick-bench.com/q/480qkw1sP4OWOH6JBxsm-J_9uOk (Adding -fno-inline may provide a clue.)