Now the backend promotes mask vector to an i8 vector and extract element from that. We could bitcast to a widen element vector, and extract from it to GPR, then use I instruction to extract the certain bit.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
4261 | Use unsigned instead of auto | |
4263 | Ele->Elt would be a more common shortening. | |
4267 | getSizeBits(). XLenVT is always scalar. | |
4274 | getSizeBits(). XLenVT is always scalar. | |
4277 | getSizeBits(). XLenVT is always scalar. | |
4279 | This shift pair can be an AND right? | |
4294 | I don't think you need to pass false here. | |
4296 | Use SDValue instead of auto. |
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
4273 | This won't work with Zve32 on RV64. A vector XLen elements wouldn't be legal. |
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-extract-i1.ll | ||
---|---|---|
68 | I don't think I understand what this subtract is doing. |
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
4261 | Done. | |
4263 | Done. | |
4267 | Done | |
4273 | I add MaxEEW to get the right largest vector element width that we could have on current target, but we do not support Zve extension now, so I just set it to 64 and add a TODO to remind changing it after having Zve. | |
4274 | Done | |
4277 | Done | |
4279 | Done | |
4294 | Done. | |
4296 | Done. | |
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-extract-i1.ll | ||
68 | We will use vmv.x.s to extract the elment to GPR, and if eew is less than XLEN, the value will be signed extend. For example, for 8 x i1 mask vector, we will have: GPR bit | XLEN -1 |--------------| 6 | 5 | 4 | 3 | 2 | 1 | 0 | mask index | 0 |--------------| 1 | 2 | 3 | 4 | 5 | 6 | 7 | So if we want to extract the 0th element, we should set extract bit index to XLEN - 1, and otherwise the index = element width - 1 - mask index. |
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-extract-i1.ll | ||
---|---|---|
68 | Why would the mask bits be in reversed order? |
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-extract-i1.ll | ||
---|---|---|
68 | It is my mistake, I thought things in wrong way. Here should not be in reversed order. I fixed it. |
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
4273 | You don't need Zve to test this. Before Zve was added to the spec we added a command line option "-riscv-v-fixed-length-vector-elen-max" to clip the ELEN. |
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
4267 | Use unsigned. Nothing here needs 64-bits. |
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
4267 | Done. |
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
4258–4259 | This comment is out of date. |
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
4260 | nit: Nums is a little unconventional. NumElts or something? You can also use getVectorNumElements because we know it's a fixed-length vector. | |
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-extract-i1.ll | ||
5 | You'll need to rebase and swap +experimental-v for +v | |
272 | This doesn't look like it's doing the right thing. We haven't modified the original extract index a1 at this point so we could be shifting an i32 right by up to 127 places? Have I missed something? |
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-extract-i1.ll | ||
---|---|---|
272 | Here we want to extract the (idx % 32)th bit from the GPR, and a1 owns the value of idx, so (idx % 32) is a1[4-0]. And because the shift instruction only uses the 0 - (log2(xlen)-1) bits of rs2, so we actually do not need to get a1[4-0], we could just use a1. So I think here is OK? |
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
4270 | I think asserting that NumElts is a power of two (or just skipping this optimization) would be useful just in case we ever support other vector types. This is quite an edge case so won't be well covered, and could silently do some weird things. | |
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-extract-i1.ll | ||
272 | Ah yes, that's what I missed. Thanks! I see there's an AND being generated anyway which should be doing the right thing. |
Address comment.
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
4270 | Thanks, I add an assert for this. |
This comment is out of date.