]> git.ipfire.org Git - thirdparty/gcc.git/commit
match.pd: Simplify popcount(X&Y)+popcount(X|Y) as popcount(X)+popcount(Y)
authorRoger Sayle <roger@nextmovesoftware.com>
Thu, 11 May 2023 07:15:21 +0000 (08:15 +0100)
committerRoger Sayle <roger@nextmovesoftware.com>
Thu, 11 May 2023 07:15:21 +0000 (08:15 +0100)
commit5fdcfe3c577657cb4d6dbc394a3c10b6a8e8cbd3
tree61a6dded8a9598eee752734aa8b783a964cac16d
parentc0dd80e4c4c332ed8c65dd96528cc2dc9e9e5ef7
match.pd: Simplify popcount(X&Y)+popcount(X|Y) as popcount(X)+popcount(Y)

This patch teaches match.pd to simplify popcount(X&Y)+popcount(X|Y) as
popcount(X)+popcount(Y), and the related simplifications that
popcount(X)+popcount(Y)-popcount(X&Y) is popcount(X|Y).  As surprising
as it might seem, this idiom is common in cheminformatics codes
(for Tanimoto coefficient calculations).

2023-05-11  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* match.pd <popcount optimizations>: Simplify popcount(X|Y) +
popcount(X&Y) as popcount(X)+popcount(Y).  Likewise, simplify
popcount(X)+popcount(Y)-popcount(X&Y) as popcount(X|Y), and
vice versa.

gcc/testsuite/ChangeLog
* gcc.dg/fold-popcount-8.c: New test case.
* gcc.dg/fold-popcount-9.c: Likewise.
* gcc.dg/fold-popcount-10.c: Likewise.
gcc/match.pd
gcc/testsuite/gcc.dg/fold-popcount-10.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/fold-popcount-8.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/fold-popcount-9.c [new file with mode: 0644]