[PATCH] middle-end: Recognize idioms for bswap32 and bswap64 in match.pd.

Roger Sayle roger@nextmovesoftware.com
Wed Aug 12 08:36:54 GMT 2020


This patch is inspired by a small code fragment in comment #3 of
bugzilla PR rtl-optimization/94804.  That snippet appears almost
unrelated to the topic of the PR, but recognizing __builtin_bswap64
from two __builtin_bswap32 calls, seems like a clever/useful trick.
GCC's optabs.c contains the inverse logic to expand bswap64 by
IORing two bswap32 calls, so this transformation/canonicalization
is safe, even on targets without suitable optab support.  But
on x86_64, the swap64 of the test case becomes a single instruction.


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


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

gcc/ChangeLog
	* match.pd (((T)bswapX(x)<<C)|bswapX(x>>C) -> bswapY(x)):
	New simplifications to recognize __builtin_bswap{32,64}.

gcc/testsuite/ChangeLog
	* gcc.dg/fold-bswap-1.c: New test.


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

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patcha2.txt
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200812/9513f74a/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patcha2b.txt
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200812/9513f74a/attachment-0001.txt>


More information about the Gcc-patches mailing list