This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Improve code generation of constant vectors
ClosedPublic

Authored by evandro on Jan 16 2018, 2:20 PM.

Details

Summary

Use the whole gamut of constant immediate values available to set up a vector. Instead of using, for example, mov w0, #0xffff; dup v0.4s, w0, which transfers between register files, use the more efficient movi v0.4s, #-1 instead. Not limited to just a few values, but any immediate value that can be encoded by all the variants of FMOV, MOVI, MVNI.

Diff Detail

Repository
rL LLVM

Event Timeline

evandro created this revision.Jan 16 2018, 2:20 PM

The case you implemented looks sensible, but I wonder if this can be implemented more generically so that the pattern can be used for other constants as well. Maybe it can be done using a ComplexPattern that encodes any (by MOVI encodable) constant as an immediate+shift and then uses those as input to MOVI. Is this something you have considered?

I have not considered ComplexPattern. That's a good idea. I'll look into it.

You should probably just fix AArch64TargetLowering::LowerBUILD_VECTOR to generate the right node in the first place. Not sure why it isn't picking up these particular cases, but it has code to handle constant BUILD_VECTORS.

Indeed, the DUPs are coming from AArch64TargetLowering::LowerBUILD_VECTOR().

Which approach would be more elegant and which would be the ups and downs of each one? On one hand, lowering seems to be more efficient in terms of compile time. On the other hand, pattern matching may be more elegant.

You want to avoid repeating all the code in AArch64TargetLowering::LowerBUILD_VECTOR which already exists for matching constants... so you probably need to fix it in LowerBUILD_VECTOR.

This comment was removed by evandro.
evandro updated this revision to Diff 135191.Feb 20 2018, 7:33 PM
evandro retitled this revision from [AArch64] Improve code generation of vector mask build to [AArch64] Improve code generation of constant vectors.
evandro edited the summary of this revision. (Show Details)
evandro added a reviewer: efriedma.
evandro removed a subscriber: efriedma.

Generalize the use of constants to set up vectors.

evandro updated this revision to Diff 135705.Feb 23 2018, 2:47 PM
evandro edited the summary of this revision. (Show Details)

Refactor a wrapper function away.

evandro added a subscriber: sebpop.Mar 1 2018, 8:10 AM

The patch looks good to me.
Thanks!

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
6615 ↗(On Diff #135705)

Please commit this NFC cleanup as a separate patch.

evandro marked an inline comment as done.Mar 1 2018, 1:20 PM
This revision was not accepted when it landed; it landed in state Needs Review.Mar 5 2018, 9:05 AM
This revision was automatically updated to reflect the committed changes.