[llvm] [DAG] Expand mask_beforefirst during promotion (PR #230163)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 9 04:13:08 PDT 2026


================
@@ -6465,6 +6465,13 @@ SDValue DAGTypeLegalizer::PromoteIntRes_GET_ACTIVE_LANE_MASK(SDNode *N) {
 SDValue DAGTypeLegalizer::PromoteIntRes_MASK_BEFOREFIRST(SDNode *N) {
   EVT VT = N->getValueType(0);
   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
+
+  // If the promoted MASK_BEFOREFIRST isn't supported by the target, try to
+  // expand now so the target can lower cttz_elts on the original mask type.
+  if (!TLI.isOperationLegalOrCustom(ISD::MASK_BEFOREFIRST, NVT))
+    return DAG.getNode(ISD::ANY_EXTEND, SDLoc(N), NVT,
+                       TLI.expandMaskBeforeFirst(N, DAG));
----------------
lukel97 wrote:

I don't think getBooleanContents matters for result promotion because the upper bits of the result are undefined. My understanding is that we need to use getBooleanContents when the node is already at a wide type e.g. get_active_lane_mask at v16i8 and we need to have a defined result for the upper bits. In which case we would use getBoolExtOrTrunc. 

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


More information about the llvm-commits mailing list