This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] use CNT for ISD::popcnt and ISD::parity if available
ClosedPublic

Authored by stuij on Nov 28 2022, 6:29 AM.

Details

Summary

These are the two places where we explicitly want to use cnt in
SelectionDAG when feature CSSC is available: ISD::popcnt and ISD::parity

For both, we need to make sure we're emitting optimized code for i32 (and
lower), i64 and i128. The most optimal way is of course using the GPR CNT
instruction. If we don't have CSSC, but we do have neon, we'll use floating
point CNT. If all fails, we'll fall back on the general GPR popcnt and parity
implementations.

spec:
https://developer.arm.com/documentation/ddi0602/2022-09/Base-Instructions/CNT--Count-bits-

Diff Detail

Event Timeline

stuij created this revision.Nov 28 2022, 6:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 28 2022, 6:29 AM
stuij requested review of this revision.Nov 28 2022, 6:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 28 2022, 6:29 AM
lenary accepted this revision.Nov 28 2022, 7:02 AM

LGTM.

This is bypassed when we mark the ISD operations as legal, because we want to directly select the ISD operations into instructions, or do the generic expansion. That implementation is still needed when we don't have these instructions though, when we mark the ISD operations for custom legalisation.

This revision is now accepted and ready to land.Nov 28 2022, 7:02 AM

No worries, but this is GlobalIsel and not SDAG.

stuij added a comment.Nov 28 2022, 7:24 AM

Oh no we are. I've got GIsel patches ready for CNT and the other CSSC instructions, which will amend amongst others that piece of code. I'm a bit busy right now, but they'll be put up for review somewhere next week.

No worries, but this is GlobalIsel and not SDAG.

Sorry, my mistake. Yeah, as Ties says, we do have patches for doing the relevant GlobalISel changes to add support for these instructions.

Matt added a subscriber: Matt.Nov 28 2022, 1:12 PM