This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add TTI support for cpop with Zbb
ClosedPublic

Authored by craig.topper on Mar 23 2021, 11:28 AM.

Details

Summary

This will tell loop idiom recognize that it can convert popcount loops
to intrinsics. I didn't bother checking for illegal types. Type legalization
knows how to split a ctpop into multiple ctops added together. Assuming we only
receive reasonable integer bit widths, a few cpop instructions added together
is probably better than the loop.

Diff Detail

Event Timeline

craig.topper created this revision.Mar 23 2021, 11:28 AM
craig.topper requested review of this revision.Mar 23 2021, 11:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 23 2021, 11:28 AM
Herald added a subscriber: MaskRay. · View Herald Transcript

Makes sense - nice. Should it test that we don't expect popcount without zbb enabled?

Sanity check: experimental-b implies experimental-zbb and so will also generate the popcount, right?

Add more test RUN lines. Use update_test_checks.py because I'm not a big fan of -NOT checks.

frasercrmck added inline comments.Mar 24 2021, 10:40 AM
llvm/test/Transforms/LoopIdiom/RISCV/popcnt.ll
29

Maybe it's late in the day but I expected there not to be a loop here. Am I missing something?

craig.topper added inline comments.Mar 24 2021, 10:48 AM
llvm/test/Transforms/LoopIdiom/RISCV/popcnt.ll
29

LoopIdiomRecognize requires other passes to do the cleanup. The main goal of LoopIdiomRecognize is to rewrite the loop into countable form. It does this by putting the ctpop outside the loop and decrement it each iteration. Other passes will need to determine that the loop doesn't do anything else and remove it.

frasercrmck accepted this revision.Mar 24 2021, 10:51 AM

LGTM

llvm/test/Transforms/LoopIdiom/RISCV/popcnt.ll
29

Oh yes I see now how the PHIs in while.end.loopexit and while.end help show that. Thanks!

This revision is now accepted and ready to land.Mar 24 2021, 10:51 AM
This revision was landed with ongoing or failed builds.Mar 24 2021, 10:59 AM
This revision was automatically updated to reflect the committed changes.