This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][GlobalISel] Legalize ctpop for v2s64, v2s32, v4s32, v4s16, v8s16
ClosedPublic

Authored by jroelofs on Jul 20 2021, 12:30 PM.

Diff Detail

Event Timeline

jroelofs created this revision.Jul 20 2021, 12:30 PM
jroelofs requested review of this revision.Jul 20 2021, 12:30 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 20 2021, 12:30 PM
paquette added inline comments.Jul 20 2021, 1:22 PM
llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
1217

doesn't SmallVector need an initial size?

1237

I think CTPOP is only used here? Maybe it's a little cleaner to move it and related stuff down near it.

1244

I don't think you should have to do this here, since we're before register bank selection?

1250

Logic here is getting a little complex. Maybe this?

if (Ty.isScalar() && Size == 64)
  MIRBuilder.buildZExt(Dst, UADD);
else
  UADD->getOperand(0).setReg(Dst);
1258

This shouldn't be necessary since we haven't selected regbanks yet.

jroelofs added inline comments.Jul 20 2021, 1:55 PM
llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
1217

Sean Silva recently added a default to it: https://reviews.llvm.org/D92522

1237

I wanted to keep HAdds near where it was used.

1244

MachineVerifier seems to expect them just after legalization:

*** Bad machine code: Virtual register does not match instruction constraint ***
- function:    s32_lower
- basic block: %bb.0  (0x7fba998570c8)
- instruction: %ctpop:_(s32) = UADDLVv8i8v %4:_(<8 x s8>)
- operand 0:   %ctpop:_
Expect register class FPR16 but got nothing
1250

👍

jroelofs updated this revision to Diff 360260.Jul 20 2021, 1:55 PM
paquette added inline comments.Jul 20 2021, 2:16 PM
llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
1244

ah, yeah I guess it's cause it's not a generic instr. :/

Maybe it would make sense to add a G_UADDLV generic instruction to avoid emitting target instrs.

IIRC we import tablegen patterns for the uaddlv intrinsic allowing us to select it easily. Maybe if we had a generic instruction, we could do something similar.

jroelofs added inline comments.Jul 20 2021, 2:33 PM
llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
1244

maybe I ought to just use the intrinsics then

jroelofs updated this revision to Diff 360279.Jul 20 2021, 2:34 PM
This revision is now accepted and ready to land.Jul 20 2021, 3:04 PM
This revision was landed with ongoing or failed builds.Jul 20 2021, 3:39 PM
This revision was automatically updated to reflect the committed changes.
llvm/test/CodeGen/AArch64/GlobalISel/legalize-ctpop.mir