[llvm-dev] [SVE][AArch64] Codegen for a scalable vector splat

Finkel, Hal J. via llvm-dev llvm-dev at lists.llvm.org
Thu Aug 29 08:52:27 PDT 2019


On 8/29/19 7:26 AM, Graham Hunter via llvm-dev wrote:
> Hi,
>
> During the discussion on introducing scalable vectors we established that we could use the canonical IR form for splats of scalable vector types (insert element into lane 0 of an undef vector, shuffle that with another undef vector of the same type and a zeroinitializer mask).
>
> We do run into a problem for lowering to SelectionDAG however, since the canonical form there is a BUILD_VECTOR with all elements being the same. This obviously doesn't work if we don't know how many elements there are. We have a couple of solutions and would like to know which the community prefers.
>
> 1) Add a new SPLAT_VECTOR ISD node. This was part of our overall RFC from 2016 and is the solution that we're currently using downstream. It just accepts a single scalar value. This has worked well with just the SVE codegen using it, but I don't know if we would run into problems if we try to make this the canonical splat form for SDAG.
>
> 2) Extend BUILD_VECTOR to accept an initial boolean indicating whether it is a splat, and if true the first element can be assumed to be the same as all others. The splat form would be the only valid use of BUILD_VECTOR for scalable vector types. For fixed length vectors we could either change existing checks for splats to only look at the flag and would only need one extra argument for the splat value, or use the flag as a shortcut and fall back to checking all the elements if there's the possibility of a fold generating a splat and it not being recognized.
>
> Given the existence of MVTs with >1000 elements per vector, the SPLAT_VECTOR or BUILD_VECTOR with single element approach may also be beneficial for some fixed length backends.


I believe that the new ISD node is the better design. It can default to 
Expand and the default expansion can fall back to the existing 
BUILD_VECTOR node (for fixed-length vectors). Thus, we can maintain 
backwards compatibility. Having a special flag on on BUILD_VECTOR that 
one needs to remember to check in order to know how to interpret the 
other node arguments seems prone to mistakes. In other words, we do 
already have a getSplatValue member on BuildVectorSDNode, and a number 
of other utility functions, but transforming those from utility 
functions to semantically-mandatory checks seems suboptimal.

  -Hal


>
> Any thoughts?
>
> -Graham
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory



More information about the llvm-dev mailing list