[llvm-dev] Adding support for vscale
Sander De Smalen via llvm-dev
llvm-dev at lists.llvm.org
Mon Sep 30 02:29:44 PDT 2019
I've posted two patches on Phabricator to add support for VScale in LLVM.
A brief recap on `vscale`:
The scalable vector type in LLVM IR is defined as `<vscale x n x m>`, to create types such as `<vscale x 16 x i8>` for a scalable vector with at least 16 bytes. In the definition of the scalable type, `vscale` is specified as a positive constant of type integer that will only be known at runtime but is guaranteed to be constant throughout the program.
The first patch  adds support for `vscale` as a symbolic constant to the LLVM IR so that it can be used in address calculations, induction variable updates and other places where the `vscale` property needs to be used to generate code for scalable vectors.
The second patch  adds the ISD::VSCALE node which, if supported by the target, can be materialised into an instruction that returns the runtime value for `vscale`. It can also be used to be folded into addressing modes, like needed for SVE/SVE2 reg+imm load/store instructions.
I'm aware that Graham has discussed this before at previous dev meetings and that some had their reservations about exposing this as a Constant explicitly. But the reasons for doing so are because the value is inherently constant. If it is not constant, this would violate the definition of the scalable type. This change enforces that. Also, vscale is expected to be used in addressing modes, so moving/hoisting or any kind of GVN/CSE would obfuscate the use of vscale for these purposes and would need to be untangled in passes like CodeGenPrep.
Hopefully the patches help clearing up any questions/reservations people may have had previously (and if not, I hope this thread can be the platform to discuss these).
More information about the llvm-dev