[PATCH] middle-end: Simplify popcount/parity of bswap/rotate.

Roger Sayle roger@nextmovesoftware.com
Fri Aug 21 16:52:31 GMT 2020


This simple patch to match.pd optimizes away bit permutation
operations, specifically bswap and rotate, in calls to popcount and
parity.  Although this patch has been developed and tested on LP64,
it relies on there being no truncations or extensions to "marry up"
the appropriate PARITY, PARITYL and PARITYLL forms with either BSWAP32
or BSWAP64, assuming this transformation won't fire if the integral
types have different sizes.

The following patch has been tested on x86_64-pc-linux-gnu with
"make bootstrap" and "make -k check" with no new failures.
Ok for mainline?

2020-08-21  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
	* gcc/match.pd (popcount(bswapN(x)) -> popcount(x),
	popcount(rotate(x)) -> popcount(x), parity(bswapN(x)) -> parity(x),
	parity(rotate(x)) -> parity(x)): New simplifications.

gcc/testsuite/ChangeLog
	* gcc.dg/fold-popcount-6.c: New test.
	* gcc.dg/fold-popcount-7.c: New test.
	* gcc.dg/fold-parity-6.c: New test.
	* gcc.dg/fold-parity-7.c: New test.

Thanks in advance,
Roger
--
Roger Sayle
NextMove Software
Cambridge, UK

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patcha.txt
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200821/1d43534e/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patchac.txt
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200821/1d43534e/attachment-0001.txt>


More information about the Gcc-patches mailing list