This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] add GlobalIsel support for scalar CNT instruction
ClosedPublic

Authored by stuij on Dec 6 2022, 5:31 AM.

Details

Summary

When feature CSSC is available we should use instruction CNT for s32, s64 and
s128 types in GlobalIsel's G_CTPOP.

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

Diff Detail

Event Timeline

stuij created this revision.Dec 6 2022, 5:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 6 2022, 5:31 AM
stuij requested review of this revision.Dec 6 2022, 5:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 6 2022, 5:31 AM
paquette added inline comments.Dec 7 2022, 10:23 AM
llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
1296–1297

Does this comment need updating with this change?

paquette added inline comments.Dec 7 2022, 2:16 PM
llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
1335

Pop1Reg and Pop2Reg are only used here. Might as well fold them into the call.

Also you can just pass in the LLT and buildAdd will automagically create a 64-bit register for you. So you can just pass s64 here.

Then, below, buildZExt can just use the 0th register of this add.

stuij updated this revision to Diff 483531.Dec 16 2022, 7:01 AM
stuij marked 2 inline comments as done.

addressed review comments

stuij added inline comments.Dec 16 2022, 7:03 AM
llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
1296–1297

yes, thanks!

1335

much cleaner :) thanks!

aemerson accepted this revision.Jan 5 2023, 12:35 AM

LGTM with some simplifications.

llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
1332

I think you can simplify even further and just do:
auto Add = MIRBuilder.buildAdd(s64, CTPOP1, CTPOP2);

1334

Same here, don't need the getReg(0)

This revision is now accepted and ready to land.Jan 5 2023, 12:35 AM
stuij updated this revision to Diff 486587.Jan 5 2023, 8:06 AM

removed lambdas, addressed review comment

stuij marked 2 inline comments as done.Jan 5 2023, 8:09 AM

removed the lambdas as with the other CSSC patches

aemerson accepted this revision.Jan 5 2023, 10:09 AM

LGTM, thanks!

This revision was landed with ongoing or failed builds.Jan 6 2023, 3:08 AM
This revision was automatically updated to reflect the committed changes.