[llvm] [VP][RISCV] Add vp.cttz.elts intrinsic and its RISC-V codegen (PR #90502)

Min-Yih Hsu via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 29 11:29:08 PDT 2024


================
@@ -9074,6 +9074,38 @@ SDValue TargetLowering::expandVPCTTZ(SDNode *Node, SelectionDAG &DAG) const {
   return DAG.getNode(ISD::VP_CTPOP, dl, VT, Tmp, Mask, VL);
 }
 
+SDValue TargetLowering::expandVPCTTZElements(SDNode *N,
+                                             SelectionDAG &DAG) const {
+  // %cond = to_bool_vec %source
+  // %splat = splat /*val=*/VL
+  // %tz = step_vector
+  // %v = vp.select %cond, /*true=*/tz, /*false=*/%splat
+  // %r = vp.reduce.umin %v
----------------
mshockwave wrote:

> If element 0 and element 1 are both zero and element 2 is non-zero

I thought in this case, we want to return 2 since there are two (i.e. element 0 and 1) zero lowest-numbered elements.

> this will return 0, but we want to return 1.

The `%cond` is a boolean vector converted from the input, if an input element is non-zero, the corresponding result element  in `%v` would be its index value (from `%tz`, which is a step_vector), which equals to the number of trailing elements. Otherwise, the result element would be EVL (from `%splat`, which is a splat of EVL). Finally we reduce.umin on `%v` so we can always find the lowest index value of non-zero elements, hence the number of trailing zero.

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


More information about the llvm-commits mailing list