https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107052
Bug ID: 107052 Summary: Range of __builtin_popcount can be improved with nonzerobits Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` void link_failure(); void f(int a) { a &= 0x300; int b = __builtin_popcount(a); if (b > 3) link_failure(); } ``` The if statement should be optimized away as the only values for popcount here is 0-3.