https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99823
--- Comment #2 from apple <ustcw0ng at mail dot ustc.edu.cn> --- (In reply to Richard Biener from comment #1) > -funroll-all-loops applies to the RTL loop unroller, the GIMPLE level > concludes: > > Estimating sizes for loop 1 > BB: 3, after_exit: 0 > size: 1 _1 = MEM[(int (*<T9564>) (int) &)__for_begin_21]; > size: 5 _13 = _1 (s_20); > size: 1 __for_begin_14 = __for_begin_21 + 8; > size: 1 ivtmp_4 = ivtmp_11 - 1; > Induction variable computation will be folded away. > size: 2 if (ivtmp_4 != 0) > Exit condition will be eliminated in peeled copies. > Exit condition will be eliminated in last copy. > Constant conditional. > BB: 5, after_exit: 1 > size: 10-3, last_iteration: 10-3 > Loop size: 10 > Estimated size after unrolling: 14 > Not unrolling loop 1: contains call and code would grow. > > so it concludes unrolling isn't profitable (but it would turn indirect into > direct calls). Anyway, I should mention here that clang can unroll it without this flag and turn out constexpr.cpp equal to unroll.cpp. And you can try to insert "#pragma GCC unroll 2“ the loop finally unrolled, even in this pragma, constexpr.cpp is not equal to unroll.cpp. But this is technically another issue