[llvm] [RISCV][GlobalISel] Legalize Scalable Vector Loads and Stores (PR #84965)

Michael Maitland via llvm-commits llvm-commits at lists.llvm.org
Tue May 28 11:11:35 PDT 2024


michaelmaitland wrote:

> When we have alignment restrictions for `load`, we need to check `allowsMemoryAccessForAlignment`, like [what SelectionDAG did](https://github.com/llvm/llvm-project/blob/16a5fd3fdb91ffb39b97dbd3a7e9346ba406360d/llvm/lib/Target/RISCV/RISCVISelLowering.cpp#L5433). Therefore, equivalently, we can insert `customIf(!allowsMemoryAccessForAlignment)` around [here](https://github.com/llvm/llvm-project/blob/3c8423d1b2bf9ae5502ed16dde1d5c23deca5fef/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp#L257)
> 
> But to get such information, we need to have `LLVMContext`, `DataLayout`, etc. However, [`RISCVLegalizerInfo`](https://github.com/llvm/llvm-project/blob/16a5fd3fdb91ffb39b97dbd3a7e9346ba406360d/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp#L69) does not have those fields in it. Nor can I figure out a way to use `LegalityQuery` to obtain those required arguments.
> 
> Can I get some help on this? Thanks!

Check out `legalizeIntrinsic` in RISCVLegalizerInfo. You can get the DataLayout from `MIRBuilder.getDataLayout()`. You can `get LLVMContext` from `MF.getFunction.getContext()`.

These are all available in `legalizeCustom` but not in the LegalityQuery, since the LegalityQuery gets built before seeing any instructions or functions. That means you will need to write a customIf that sends us to legalizeCustom more circumstances than are actually legal -- we will likely have to return false in some instances from legalizeCustom.


https://github.com/llvm/llvm-project/pull/84965


More information about the llvm-commits mailing list