[PATCH] D139512: [RISCV] Use vcpop.m to extract the first element from mask vector.

Jianjian Guan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 7 22:59:12 PST 2022


jacquesguan added inline comments.


================
Comment at: llvm/test/CodeGen/RISCV/rvv/extractelt-i1.ll:223
+; CHECK-NEXT:    vmseq.vi v8, v8, 0
+; CHECK-NEXT:    vsetivli zero, 1, e8, mf8, ta, ma
+; CHECK-NEXT:    vcpop.m a0, v8
----------------
reames wrote:
> Hm, having a vsetvli toggle here is unfortunate.  Can we achieve this in a slightly different way?
> 
> We could use a id vector, comparison with index, and then and to form a mask which could then be popcnt.  This also generalize for any index.
> 
> We could use a vfirst.m and a scalar comparison against 0.  This only works when index is the first potentially set bit.
> 
> We could extract the bottom ETYPE bits of the mask into a scalar, and then mask out the low bit.  This works for any index < min(XLEN, sizeinbits(ETYPE)).  
> 
> Have you given these options (or others) consideration?  Your chosen solution appears correct, I'm just looking for some discussion of what other options you considered and rejected before we land this.  
> 
Let me summarize:

1, For all index:
vmv + vmseq // create index mask
vcpop.m // extract the element

This way uses 3 instruction which is same as the current method, I don't think this way is better.

2, For the fisrt element:

vfirst.m + sltu

This way will change the vsetvli instruction with a scalar comparison instruction, I think it should be better as maybe avoid potential vsetvl insertion.

3, For the index located in min(XLEN, sizeinbits(ETYPE)):

This alreay achieved with fixed vector, but the scalable vector should be improved.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139512/new/

https://reviews.llvm.org/D139512



More information about the llvm-commits mailing list