Here is the final version of this patch, implementing Richard's latest suggestion, as committed to mainline. This revision has been tested on x86_64-pc-linux-gnu with a "make bootstrap" and "make -k check" with no new regressions. Many thanks for the helpful feedback about match.pd's BUILT_IN_ iterators; I'll post a follow-up patch to clean-up/make use of this idiom elsewhere in match.pd, as it is much nicer. Cheers, Roger -- -----Original Message----- From: Richard Biener Sent: 23 July 2020 10:02 To: GCC Patches Cc: Roger Sayle Subject: Re: [PATCH] middle-end: Fold popcount(x&4) to (x>>2)&1 and friends. On Thu, Jul 23, 2020 at 10:15 AM Marc Glisse wrote: > > On Wed, 22 Jul 2020, Roger Sayle wrote: > > > Many thanks for the peer review and feedback. I completely agree > > that POPCOUNT and PARITY iterators simplifies things and handle the IFN_ variants. > > Is there a reason why the iterators cannot be used for this one? > > +(for popcount (BUILT_IN_POPCOUNT BUILT_IN_POPCOUNTL BUILT_IN_POPCOUNTLL > + BUILT_IN_POPCOUNTIMAX) > + parity (BUILT_IN_PARITY BUILT_IN_PARITYL BUILT_IN_PARITYLL > + BUILT_IN_PARITYIMAX) > + (simplify > + (bit_and (popcount @0) integer_onep) > + (parity @0))) I should indeed work fine to even do (simplify (bit_and (POPCOUNT @0) integer_onep) (PARITY @0)) Likewise for the existing +/* popcount(X) == 0 is X == 0, and related (in)equalities. */ (for +popcount (POPCOUNT) (for cmp (le eq ne gt) rep (eq eq ne ne) (simplify (cmp (popcount @0) integer_zerop) (rep @0 { build_zero_cst (TREE_TYPE (@0)); })))) you can elide the (for ...) OK with those changes. Richard. > > -- > Marc Glisse