]> git.ipfire.org Git - thirdparty/gcc.git/commit
match.pd: Optimize .PARITY (.BITREVERSE (x))
authorJakub Jelinek <jakub@redhat.com>
Thu, 30 Jul 2026 07:53:50 +0000 (09:53 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 30 Jul 2026 07:55:49 +0000 (09:55 +0200)
commit1e5dca08d72f83a6c4ea3bcd2f7cc80bdfd6fc0b
treedccbf38505f2e8e727f852c93e01f69733bf3970
parent1f4cc0f7a14b52fdfbd02ac890cc7aedbdfb1979
match.pd: Optimize .PARITY (.BITREVERSE (x))

When working on the last patch, I've noticed that the parity(bswap(x))
optimization only optimizes the 16/32/64/128-bit bswaps, but not
generic _BitInt bswap, and doesn't optimize any of the bitreverses.
Both all bswap and all bitreverse builtins/ifns preserve values of all the
bits, just permute them, so parity (and popcount too) can be optimized.

2026-07-30  Jakub Jelinek  <jakub@redhat.com>

* match.pd (parity(bswap(x)) is parity(x)): Use BSWAP BITREVERSE
instead of BUILT_IN_BSWAP16 BUILT_IN_BSWAP32 BUILT_IN_BSWAP64
BUILT_IN_BSWAP128.

* gcc.dg/bitint-140.c: New test.

Reviewed-by: Richard Biener <rguenth@suse.de>
gcc/match.pd
gcc/testsuite/gcc.dg/bitint-140.c [new file with mode: 0644]