[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
Mon Nov 20 09:15:24 PST 2023
jiahanxie353 wrote:
I found that to get things working, I should be using
```C++
{
nxv1s8, nxv2s8, nxv4s8, nxv8s8, nxv16s8, nxv32s8, nxv64s8, nxv1s16,
nxv2s16, nxv4s16, nxv8s16, nxv16s16, nxv32s16, nxv1s32, nxv2s32, nxv4s32,
nxv8s32, nxv16s32, nxv1s64, nxv2s64, nxv4s64, nxv8s64
}
```
in-place instead of declaring it as an `std::initializer_list<LLT>` because otherwise the tests are just failing.
Something like
```cpp
legalFor([=, &ST](const LegalityQuery &Query) {
return ST.hasVInstruction() && typeInSet(0, {
nxv1s8, nxv2s8, nxv4s8, nxv8s8, nxv16s8, nxv32s8, nxv64s8, nxv1s16,
nxv2s16, nxv4s16, nxv8s16, nxv16s16, nxv32s16, nxv1s32, nxv2s32, nxv4s32,
nxv8s32, nxv16s32, nxv1s64, nxv2s64, nxv4s64, nxv8s64
})(Query) &&
(Query.Types[0].getScalarSize() != 64 || ST.hasVInstruction64()) &&
(Query.Types[0].getElementCount().getKnownMinValue() != 1 || ST.getELEN() == 64));
}
```
works but not
```c++
.legalFor([=, &ST](const LegalityQuery &Query) {
return ST.hasVInstruction() && typeInSet(0, AllVecTys)(Query) &&
(Query.Types[0].getScalarSize() != 64 || ST.hasVInstruction64()) &&
(Query.Types[0].getElementCount().getKnownMinValue() != 1 || ST.getELEN() == 64));
}
```
I haven't delved too deep but I think it has to do with the temporal behavior of `std::initializer_list<LLT>`. My reasoning is that the temporary array created for nitializer_list<LLT> exists only during the initialization of `AllVecTypes`. Once the initializer list has been used to initialize it, the temporary array goes out of scope, and the elements of `AllVecTypes` are left pointing to somewhere unknown.
What's your insight into this behavior and what's your opinion on implementation @michaelmaitland @topperc ? I mean using them in-place works, but it's clumsy.
https://github.com/llvm/llvm-project/pull/71400
More information about the llvm-commits
mailing list