This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Introduce MVETRUNC ISel lowering
ClosedPublic

Authored by dmgreen on Nov 21 2020, 12:17 PM.

Details

Summary

Currently, when encountering store(trunc(..)) where the trunc is double a legal vector in MVE, we spilt the node into two different stores each performing half of the trunc from the wider type. This works well for efficiently lowering widen than legal types (else the trunc becomes a series of individual lane moves). Unfortunately this splitting is currently one of the first combines attempted, so can happen before any other combines, which might be more preferable.

This patch instead introduces the concept of a MVETRUNC ISel node that the trunk is initially lowered to, to keep it intact as a single item as opposed to splitting it up. This allows us to push the store(trunc(..)) combine later, allowing other optimisations to potentially happen on the trunc first. The store(trunc(..)) splitting can then be done later in the legalisation period if needed, or else fall back to a buildvector as before.

This can also be used in the future to lower to loads/stores, as opposed to the more expensive lane extracts/inserts.

Some extra combines are added to keep all the existing tests happy. This is perhaps not the most elegant thing in the world, but does help as can be seen some of the tests. It can also possibly be extended in the future to lower to a stack load/store, which may be more efficient than the expanding at the expense of a stack slot.

Diff Detail

Event Timeline

dmgreen created this revision.Nov 21 2020, 12:17 PM
dmgreen requested review of this revision.Nov 21 2020, 12:17 PM
samtebbs added inline comments.Jan 8 2021, 6:38 AM
llvm/lib/Target/ARM/ARMISelLowering.h
54

Can we instead delay the splitting of a truncate instead of coining a new node for it? I suppose that future stages in the pipeline may depend on it being legal so the splitting would have to happen early.

dmgreen updated this revision to Diff 352950.Jun 18 2021, 3:00 AM
dmgreen edited the summary of this revision. (Show Details)

Sorry about the very long delay. Other things came up, but I still think this is worthwhile. It feels a little odd to introduce a target node that isn't legal, but it helps in the lowering of truncates under MVE. It should allow us to, instead of expanding the trunc into a lot of lane extract/insert operations, lower them to two truncating stack stores and a reload (which I will do as a separate patch). We can then do the same for zext/sext, which should help improve the worst case lowering for a lot of zext/sext/trunc we currently see. And help with the lowering of nodes like VABD like we see here, and things like VMULL and certain vector reductions.

samtebbs accepted this revision.Jun 23 2021, 10:03 AM

That makes sense to me. It's worth adding a new node if it will help improve lowering for other instructions too. LGTM!

This revision is now accepted and ready to land.Jun 23 2021, 10:03 AM
This revision was landed with ongoing or failed builds.Jun 26 2021, 2:00 PM
This revision was automatically updated to reflect the committed changes.