This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] ctpop(X) ^ ctpop(Y) & 1 --> ctpop(X^Y) & 1 (PR50094)
ClosedPublic

Authored by xbolva00 on May 3 2021, 5:04 PM.

Details

Summary

Original pattern: (builtin_parity(x) ^ builtin_parity(y))

LLVM rewrites it as: (builtin_popcount(x) ^ builtin_popcount(y)) & 1

Optimized form: __builtin_popcount(X^Y) & 1

Alive proof: https://alive2.llvm.org/ce/z/-GdWFr

Diff Detail

Event Timeline

xbolva00 created this revision.May 3 2021, 5:04 PM
xbolva00 requested review of this revision.May 3 2021, 5:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 3 2021, 5:04 PM
RKSimon accepted this revision.May 4 2021, 4:01 AM

LGTM with one minor

llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
227
// (ctpop(X) ^ ctpop(Y)) & 1 --> ctpop(X^Y) & 1
This revision is now accepted and ready to land.May 4 2021, 4:01 AM
xbolva00 added inline comments.May 4 2021, 4:13 AM
llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
227

Yeah, thx