[llvm] [SelectionDAG] Expand CTTZ_ELTS[_ZERO_POISON] and handle legalization (PR #188691)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 30 04:08:00 PDT 2026


================
@@ -1221,6 +1225,18 @@ SDValue DAGTypeLegalizer::ScalarizeVecOp_VECTOR_FIND_LAST_ACTIVE(SDNode *N) {
   return DAG.getConstant(0, SDLoc(N), VT);
 }
 
+SDValue DAGTypeLegalizer::ScalarizeVecOp_CTTZ_ELTS(SDNode *N) {
+  // The number of trailing zero elements is 1 if the element is 0, and 0
+  // otherwise.
+  if (N->getOpcode() == ISD::CTTZ_ELTS_ZERO_POISON)
+    return DAG.getConstant(0, SDLoc(N), N->getValueType(0));
+  SDValue Op = GetScalarizedVector(N->getOperand(0));
+  SDValue SetCC =
+      DAG.getSetCC(SDLoc(N), MVT::i1, Op,
----------------
lukel97 wrote:

I think that would mean that the contents aren't guaranteed to have only the first bit set when true, i.e. dependent on TLI.getBooleanContents. We need only the first bit to be set since we rely on the zext below to produce one. FWIW `DAGTypeLegalizer::ScalarizeVecOp_VSETCC` seems to create a `MVT::i1` SETCC too. 

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


More information about the llvm-commits mailing list