[llvm] [RISCV][GlobalISel] Legalize G_ADD, G_SUB, G_AND, G_OR, G_XOR on RISC-V Vector Extension (PR #71400)

Jiahan Xie via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 14 05:45:35 PST 2023


jiahanxie353 wrote:

Given different conditions
> nxv1s64, nxv2s64, nxv4s64, nxv8s64 require hasVInstructionsI64 instead of hasVInstructions

> nxv1s8, nxv1s16, nxv1s32 require Subtarget.getELen() == 64

I have this literal implementation locally:
```C++
getActionDefinitionsBuilder({G_ADD, G_SUB, G_AND, G_OR, G_XOR})
        .legalFor({s32, sXLen})
        .legalFor(ST.hasVInstructions()
                      ? std::initializer_list<LLT>{nxv2s8, nxv4s8, nxv8s8,
                                                   nxv16s8, nxv32s8, nxv64s8,
                                                   nxv2s16, nxv4s16, nxv8s16,
                                                   nxv16s16, nxv32s16, nxv2s32,
                                                   nxv4s32, nxv8s32, nxv16s32}
                      : std::initializer_list<LLT>())
        .legalFor(
            ST.hasVInstructionsI64()
                ? std::initializer_list<LLT>{nxv1s64, nxv2s64, nxv4s64, nxv8s64}
                : std::initializer_list<LLT>())
        .legalFor(ST.getELen() == 64
                      ? std::initializer_list<LLT>{nxv1s8, nxv1s16, nxv1s32}
                      : std::initializer_list<LLT>())
        .widenScalarToNextPow2(0)
        .clampScalar(0, s32, sXLen);
```
Please point out any issue this code snippet has.

In addition, it has to have fragments of `AllVecTys`, so I was wondering, as per @michaelmaitland 's review:
> In any case, I'd like to have AllVecTys exist so it can be reused by future patches.

Shall we still be declaring `AllVecTys`? It's good to declare it because it's likely to be reused, what if future patches also need the aforementioned condition checking, is it still worth it?

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


More information about the llvm-commits mailing list