https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111791
--- Comment #4 from Robin Dapp <rdapp at gcc dot gnu.org> --- This is a scalar popcount and as Kito already noted we will just emit cpop a0, a0 once the zbb extension is present. As to the question what is actually being vectorized here, I'm not so sure :D It looks like we're generating a vectorized scalar popcount by something like a reduction? But we already did the call to __popcountdi2? Analyzing loop at pr111791.c:8 pr111791.c:8:25: note: === analyze_loop_nest === pr111791.c:8:25: note: === vect_analyze_loop_form === pr111791.c:8:25: note: === get_loop_niters === Matching expression match.pd:1919, generic-match-8.cc:27 Applying pattern match.pd:1975, generic-match-2.cc:4670 Matching expression match.pd:2707, generic-match-4.cc:36 Matching expression match.pd:2710, generic-match-3.cc:53 Matching expression match.pd:2717, generic-match-2.cc:23 Matching expression match.pd:2707, generic-match-4.cc:36 Matching expression match.pd:2710, generic-match-3.cc:53 Matching expression match.pd:2717, generic-match-2.cc:23 Matching expression match.pd:2707, generic-match-4.cc:36 Matching expression match.pd:2710, generic-match-3.cc:53 Matching expression match.pd:2717, generic-match-2.cc:23 Matching expression match.pd:148, generic-match-10.cc:27 Matching expression match.pd:148, generic-match-10.cc:27 Applying pattern match.pd:4519, generic-match-4.cc:2923 Applying pattern match.pd:201, generic-match-4.cc:3103 Applying pattern match.pd:3393, generic-match-2.cc:182 pr111791.c:8:25: note: Symbolic number of iterations is (unsigned intD.4) __builtin_popcountlD.1952 (value_4(D)) Ah, interesting: ranger(?) recognizes that the loop runs "popcount" iterations. Shouldn't that still be 64? Well, it probably knows better :) Regardless, we use this symbolic value as number of iterations: _5 = __builtin_popcountlD.1952 (value_4(D)); niters.4_9 = (unsigned intD.4) _5; _2 = __builtin_popcountlD.1952 (value_4(D)); bnd.5_3 = (unsigned intD.4) _2; _23 = (unsigned long) bnd.5_3; Then, it gets funnier: # nbits_11 = PHI <nbits_7(6), 0(5)> # vect_vec_iv_.6_15 = PHI <_16(6), { 0, 1, 2, ... }(5)> # ivtmp_24 = PHI <ivtmp_25(6), _23(5)> _26 = .SELECT_VL (ivtmp_24, POLY_INT_CST [4, 4]); _16 = vect_vec_iv_.6_15 + { POLY_INT_CST [4, 4], ... }; vect_nbits_7.7_18 = vect_vec_iv_.6_15 + { 1, ... }; # RANGE [irange] int [1, 65] nbits_7 = nbits_11 + 1; # RANGE [irange] long unsigned int [0, 18446744073709551614] _1 = value_10 + 18446744073709551615; # RANGE [irange] long unsigned int [0, 18446744073709551614] value_8 = _1 & value_10; ivtmp_25 = ivtmp_24 - _26; i.e. we have a vector IV that we add to the vectorized nbits. Finally we extract the niter-th (=popcount) element from that vector only to get - popcount :) Still not sure why that happens but a vector-mode popcount expander doesn't help here as everything is scalar. Maybe the explanation is simple in that we would vectorize such a loop anyway and here it just looks particularly bad because we already know the result via ranger?