@@ -29096,6 +29096,16 @@ uint64_t getGFNICtrlImm(unsigned Opcode, unsigned Amt = 0) {
29096
29096
llvm_unreachable("Unsupported GFNI opcode");
29097
29097
}
29098
29098
29099
+ // Generate a GFNI gf2p8affine bitmask for vXi8 bitreverse/shift/rotate.
29100
+ SDValue getGFNICtrlMask(unsigned Opcode, SelectionDAG &DAG, const SDLoc &DL, MVT VT,
29101
+ unsigned Amt = 0) {
29102
+ assert(VT.getVectorElementType() == MVT::i8 &&
29103
+ (VT.getSizeInBits() % 64) == 0 && "Illegal GFNI control type");
29104
+ uint64_t Imm = getGFNICtrlImm(Opcode, Amt);
29105
+ MVT MaskVT = MVT::getVectorVT(MVT::i64, VT.getSizeInBits() / 64);
29106
+ return DAG.getBitcast(VT, DAG.getConstant(Imm, DL, MaskVT));
29107
+ }
29108
+
29099
29109
// Return true if the required (according to Opcode) shift-imm form is natively
29100
29110
// supported by the Subtarget
29101
29111
static bool supportedVectorShiftWithImm(EVT VT, const X86Subtarget &Subtarget,
@@ -29284,9 +29294,7 @@ static SDValue LowerShiftByScalarImmediate(SDValue Op, SelectionDAG &DAG,
29284
29294
return SDValue();
29285
29295
29286
29296
if (Subtarget.hasGFNI()) {
29287
- uint64_t ShiftMask = getGFNICtrlImm(Op.getOpcode(), ShiftAmt);
29288
- MVT MaskVT = MVT::getVectorVT(MVT::i64, NumElts / 8);
29289
- SDValue Mask = DAG.getBitcast(VT, DAG.getConstant(ShiftMask, dl, MaskVT));
29297
+ SDValue Mask = getGFNICtrlMask(Op.getOpcode(), DAG, dl, VT, ShiftAmt);
29290
29298
return DAG.getNode(X86ISD::GF2P8AFFINEQB, dl, VT, R, Mask,
29291
29299
DAG.getTargetConstant(0, dl, MVT::i8));
29292
29300
}
@@ -30191,9 +30199,7 @@ static SDValue LowerRotate(SDValue Op, const X86Subtarget &Subtarget,
30191
30199
if (IsCstSplat && Subtarget.hasGFNI() && VT.getScalarType() == MVT::i8 &&
30192
30200
DAG.getTargetLoweringInfo().isTypeLegal(VT)) {
30193
30201
uint64_t RotAmt = CstSplatValue.urem(EltSizeInBits);
30194
- uint64_t RotMask = getGFNICtrlImm(Opcode, RotAmt);
30195
- MVT MaskVT = MVT::getVectorVT(MVT::i64, VT.getSizeInBits() / 64);
30196
- SDValue Mask = DAG.getBitcast(VT, DAG.getConstant(RotMask, DL, MaskVT));
30202
+ SDValue Mask = getGFNICtrlMask(Opcode, DAG, DL, VT, RotAmt);
30197
30203
return DAG.getNode(X86ISD::GF2P8AFFINEQB, DL, VT, R, Mask,
30198
30204
DAG.getTargetConstant(0, DL, MVT::i8));
30199
30205
}
@@ -31528,10 +31534,7 @@ static SDValue LowerBITREVERSE(SDValue Op, const X86Subtarget &Subtarget,
31528
31534
31529
31535
// If we have GFNI, we can use GF2P8AFFINEQB to reverse the bits.
31530
31536
if (Subtarget.hasGFNI()) {
31531
- MVT MatrixVT = MVT::getVectorVT(MVT::i64, NumElts / 8);
31532
- SDValue Matrix =
31533
- DAG.getConstant(getGFNICtrlImm(ISD::BITREVERSE), DL, MatrixVT);
31534
- Matrix = DAG.getBitcast(VT, Matrix);
31537
+ SDValue Matrix = getGFNICtrlMask(ISD::BITREVERSE, DAG, DL, VT);
31535
31538
return DAG.getNode(X86ISD::GF2P8AFFINEQB, DL, VT, In, Matrix,
31536
31539
DAG.getTargetConstant(0, DL, MVT::i8));
31537
31540
}
0 commit comments