On Sat, Dec 5, 2020 at 11:48 AM andre maute <andre.maute@xxxxxx> wrote: > I'm wondering why is there a special optimization > for the "trick" code, and why isn't there one for the "naive" code? > Because a bug report was submitted for the example that you are calling trick code. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82479 and a patch was written to fix that. The bug report says this code is present in spec2017, which is why they wanted it optimized., and why a volunteer was willing to write the complicated code necessary to perform this optimization. Anyways, yes, I'd call this a missing optimization, though likely of limited interest, unless you can point at a benchmark or important program that really needs it. You are welcome to submit a bug report, and maybe point back at bug 82479. But in general, you are better off calling __builtin_popcount. Jim