[llvm] [X86] Use GFNI for LZCNT vXi8 ops (PR #141888)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 1 20:00:34 PDT 2025


================
@@ -28998,6 +28998,35 @@ static SDValue LowerVectorCTLZ(SDValue Op, const SDLoc &DL,
   assert(Subtarget.hasSSSE3() && "Expected SSSE3 support for PSHUFB");
   return LowerVectorCTLZInRegLUT(Op, DL, Subtarget, DAG);
 }
+static SDValue LowerVectorCTLZ_GFNI(SDValue Op, SelectionDAG &DAG,
+                                    const X86Subtarget &Subtarget) {
+  SDLoc dl(Op);
+  MVT VT = Op.getSimpleValueType();
+  SDValue Input = Op.getOperand(0);
+
+  if (!VT.isVector() || VT.getVectorElementType() != MVT::i8)
+    return SDValue();
+  SmallVector<SDValue, 16> MatrixVals;
+  for (unsigned i = 0; i < VT.getVectorNumElements(); ++i) {
+    uint8_t mask = 1 << (7 - (i % 8));
+    MatrixVals.push_back(DAG.getConstant(mask, dl, MVT::i8));
+  }
+
+  SDValue Matrix = DAG.getBuildVector(VT, dl, MatrixVals);
----------------
houngkoungting wrote:

HI @RKSimon 
I'm still new to LLVM development and I have a question.
LLVM has a huge number of functions and APIs, and I often find it difficult to know which one to use when writing a new pass or transformation.

Usually, I try to Google or search through the document, but it often takes me a lot of time and feels inefficient.

Do you have any suggestions or workflows for how to better discover or learn the right LLVM functions to use in different situations?

Any tips would be greatly appreciated. Thanks!     @houngkoungting      we3223 at gmail.com

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


More information about the llvm-commits mailing list