[llvm] Perform bitreverse using AVX512 GFNI for i32 and i64. (PR #81764)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 28 05:21:52 PST 2024


================
@@ -31040,17 +31044,63 @@ static SDValue LowerBITREVERSE_XOP(SDValue Op, SelectionDAG &DAG) {
   return DAG.getBitcast(VT, Res);
 }
 
+static auto createBSWAPShuffleMask(EVT VT) {
+  SmallVector<int, 16> ShuffleMask;
+  int ScalarSizeInBytes = VT.getScalarSizeInBits() / 8;
+  for (int I = 0, E = VT.getVectorNumElements(); I != E; ++I)
+    for (int J = ScalarSizeInBytes - 1; J >= 0; --J)
+      ShuffleMask.push_back((I * ScalarSizeInBytes) + J);
+
+  return ShuffleMask;
+}
+
 static SDValue LowerBITREVERSE(SDValue Op, const X86Subtarget &Subtarget,
                                SelectionDAG &DAG) {
   MVT VT = Op.getSimpleValueType();
+  SDValue In = Op.getOperand(0);
+  SDLoc DL(Op);
+
----------------
RKSimon wrote:

Actually, that's not going to work as LowerBITREVERSE_XOP  folds the bswap into the VPPERM shuffle - we need our own implementation:
```cpp
  if (!VT.isVector()) {
    MVT VecVT = MVT::getVectorVT(VT, 128 / VT.getSizeInBits());
    SDValue Res = VT == MVT::i8 ? In : DAG.getNode(ISD::BSWAP, DL, VT, In);
    Res = DAG.getNode(ISD::SCALAR_TO_VECTOR, DL, VecVT, Res);
    Res = DAG.getBitcast(MVT::v16i8, Res);
    Res = DAG.getNode(ISD::BITREVERSE, DL, MVT::v16i8, Res);
    Res = DAG.getBitcast(VecVT, Res);
    return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT, Res,
                       DAG.getIntPtrConstant(0, DL));
  }
```

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


More information about the llvm-commits mailing list