This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][GlobalISel] Add G_VECREDUCE fewerElements support for full scalarization.
ClosedPublic

Authored by aemerson on Aug 18 2021, 12:37 AM.

Details

Summary

For some reductions like G_VECREDUCE_OR on AArch64, we need to scalarize
completely if the source is <= 64b. This change adds support for that in
the legalizer. If the source has a pow-2 num elements, then we can do
a tree reduction using the scalar operation in the individual elements.
Otherwise, we just create a sequential chain of operations.

For AArch64, we only need to scalarize if the input is <64b. If it's great than
64b then we can first do a fewElements step to 64b, taking advantage of vector
instructions until we reach the point of scalarization.

I also had to relax the verifier checks for reductions because the intrinsics
support <1 x EltTy> types, which we lower to scalars for GlobalISel.

There are still some codegen deficiencies in the generated code, but those can
be addressed later.

Diff Detail

Event Timeline

aemerson created this revision.Aug 18 2021, 12:37 AM
aemerson requested review of this revision.Aug 18 2021, 12:37 AM
paquette added inline comments.Aug 18 2021, 4:38 PM
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
7415

I think this assert should be something in the verifier?

aemerson updated this revision to Diff 367537.Aug 19 2021, 10:03 AM

Remove redundant assert.

paquette added inline comments.Aug 19 2021, 1:58 PM
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
4693

Maybe in a later patch it would be good to add a wrapper for these instructions which has an isSequential function

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

Can this happen? Looks like the MachineVerifier doesn't permit scalar sources?

paquette accepted this revision.Aug 19 2021, 3:31 PM

(LGTM with nit on legalizer rule)

This revision is now accepted and ready to land.Aug 19 2021, 3:31 PM
aemerson added inline comments.Aug 19 2021, 4:29 PM
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
4693

Sure.

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

In this patch I'm also relaxing that constraint in the verifier, because <1 x sN> vectors are indistinguishable from scalars in LLT.

This revision was landed with ongoing or failed builds.Aug 19 2021, 4:38 PM
This revision was automatically updated to reflect the committed changes.