[llvm] [SDAG] Implement missing legalization for `ISD::VECTOR_FIND_LAST_ACTIVE` (PR #180290)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 9 08:44:29 PST 2026


================
@@ -3732,6 +3735,34 @@ bool DAGTypeLegalizer::SplitVectorOperand(SDNode *N, unsigned OpNo) {
   return false;
 }
 
+SDValue DAGTypeLegalizer::SplitVecOp_VECTOR_FIND_LAST_ACTIVE(SDNode *N) {
+  SDLoc DL(N);
+
+  SDValue LoMask, HiMask;
+  GetSplitVector(N->getOperand(0), LoMask, HiMask);
+
+  EVT VT = N->getValueType(0);
+  EVT SplitVT = LoMask.getValueType();
+  ElementCount SplitEC = SplitVT.getVectorElementCount();
+
+  // Find the last active in both the low and the high masks.
+  SDValue LoFind = DAG.getNode(ISD::VECTOR_FIND_LAST_ACTIVE, DL, VT, LoMask);
+  SDValue HiFind = DAG.getNode(ISD::VECTOR_FIND_LAST_ACTIVE, DL, VT, HiMask);
+
+  // Check if any lane is active in the high mask.
+  // FIXME: This would not be necessary if VECTOR_FIND_LAST_ACTIVE returned a
+  // sentinel value for "none active".
----------------
sdesmalen-arm wrote:

It seems in SelectionDAGBuilder it creates a select (similar to what you've done here) for the passthru value when the mask is all zero, so the predicate mask can't be all-zero and it's indeed unspecified what the result of `VECTOR_FIND_LAST_ACTIVE` is otherwise (e.g. for a split vector case like here).

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


More information about the llvm-commits mailing list