[llvm] [AArch64] Lower fixed find_last_active to LASTP with SVE2.2 (PR #222534)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 04:03:02 PDT 2026


================
@@ -8283,6 +8293,36 @@ SDValue AArch64TargetLowering::LowerVECTOR_COMPRESS(SDValue Op,
                      Passthru);
 }
 
+SDValue
+AArch64TargetLowering::LowerVECTOR_FIND_LAST_ACTIVE(SDValue Op,
+                                                    SelectionDAG &DAG) const {
+  assert((Subtarget->hasSVE2p2() || Subtarget->hasSME2p2()) &&
+         "custom lowering requires LASTP");
+  SDVTList VTs = DAG.getVTList(Op.getValueType(), MVT::i32);
+  return DAG.getNode(AArch64ISD::FIND_LAST_ACTIVE, SDLoc(Op), VTs,
+                     Op.getOperand(0));
+}
+
+SDValue AArch64TargetLowering::expandFindLastActive(SDValue Op,
----------------
Lukacma wrote:

I don't quite agree with this: 
>So, the output of this node must be a valid index even in the all zero case. 
As far as I can see, what should happen when VECTOR_FIND_LAST_ACTIVE is passed all inactive mask, is not defined anywhere. This is confirmed by [previous discussion on this topic](https://github.com/llvm/llvm-project/pull/180290#discussion_r2781849351). That is because the only use of VECTOR_FIND_LAST_ACTIVE is in lowering experimental_vector_extract_last_active and there we already have a check through VECREDUCE_OR node to see if the mask is all inactive. So I think for this lowering we can ignore the all inactive lane case and just assume it is handled by surrounding code. 

For point 2 I think this optimization should a separate patch, as it seems to be unnecessary to lowering of  VECTOR_FIND_LAST_ACTIVE into LASTP ? It will make it easier to review and  see how that combine improved the codegen. Are you okay with doing that ? 

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


More information about the llvm-commits mailing list