@@ -696,12 +696,20 @@ static SDValue supplementPackedReplication(SDValue Op, SelectionDAG &DAG) {
696696 return DAG.getNode (VEISD::VEC_BROADCAST, DL, VT, {ReplOp, VLOp});
697697}
698698
699- bool isMaskType (EVT VT) {
700- if (!VT.isVector ())
701- return false ;
699+ MVT getLegalVectorType (Packing P, MVT ElemVT) {
700+ return MVT::getVectorVT (ElemVT, P == Packing::Normal ? StandardVectorWidth
701+ : PackedVectorWidth);
702+ }
702703
703- // an actual bit mask type
704- return VT.getVectorElementType () == MVT::i1;
704+ Packing getTypePacking (EVT VT) {
705+ assert (VT.isVector ());
706+ return isPackedVectorType (VT) ? Packing::Dense : Packing::Normal;
707+ }
708+
709+ bool isMaskType (EVT SomeVT) {
710+ if (!SomeVT.isVector ())
711+ return false ;
712+ return SomeVT.getVectorElementType () == MVT::i1;
705713}
706714
707715bool maySafelyIgnoreMask (unsigned VVPOpcode) {
@@ -1085,6 +1093,48 @@ SDValue VECustomDAG::getConstant(uint64_t Val, EVT VT, bool IsTarget,
10851093
10861094void VECustomDAG::dumpValue (SDValue V) const { V->print (dbgs (), &DAG); }
10871095
1096+ SDValue VECustomDAG::getConstantMask (Packing Packing, bool AllTrue) const {
1097+ auto MaskVT = getLegalVectorType (Packing, MVT::i1);
1098+
1099+ // VEISelDAGtoDAG will replace this pattern with the constant-true VM.
1100+ auto TrueVal = DAG.getConstant (-1 , DL, MVT::i32 );
1101+ auto AVL = getConstant (MaskVT.getVectorNumElements (), MVT::i32 );
1102+ auto Res = getNode (VEISD::VEC_BROADCAST, MaskVT, {TrueVal, AVL});
1103+ if (AllTrue)
1104+ return Res;
1105+
1106+ return DAG.getNOT (DL, Res, Res.getValueType ());
1107+ }
1108+
1109+ SDValue VECustomDAG::getMaskBroadcast (EVT ResultVT, SDValue Scalar,
1110+ SDValue AVL) const {
1111+ // Constant mask splat.
1112+ if (auto BcConst = dyn_cast<ConstantSDNode>(Scalar))
1113+ return getConstantMask (getTypePacking (ResultVT),
1114+ BcConst->getSExtValue () != 0 );
1115+
1116+ // Expand the broadcast to a vector comparison.
1117+ auto ScalarBoolVT = Scalar.getSimpleValueType ();
1118+ assert (ScalarBoolVT == MVT::i32 );
1119+
1120+ // Cast to i32 ty.
1121+ SDValue CmpElem = DAG.getSExtOrTrunc (Scalar, DL, MVT::i32 );
1122+ unsigned ElemCount = ResultVT.getVectorNumElements ();
1123+ MVT CmpVecTy = MVT::getVectorVT (ScalarBoolVT, ElemCount);
1124+
1125+ // Broadcast to vector.
1126+ SDValue BCVec =
1127+ DAG.getNode (VEISD::VEC_BROADCAST, DL, CmpVecTy, {CmpElem, AVL});
1128+ SDValue ZeroVec =
1129+ getBroadcast (CmpVecTy, {DAG.getConstant (0 , DL, ScalarBoolVT)}, AVL);
1130+
1131+ MVT BoolVecTy = MVT::getVectorVT (MVT::i1, ElemCount);
1132+
1133+ // Broadcast(Data) != Broadcast(0)
1134+ // TODO: Use a VVP operation for this.
1135+ return DAG.getSetCC (DL, BoolVecTy, BCVec, ZeroVec, ISD::CondCode::SETNE);
1136+ }
1137+
10881138SDValue VECustomDAG::getVectorExtract (SDValue VecV, SDValue IdxV) const {
10891139 assert (VecV.getValueType ().isVector ());
10901140 auto ElemVT = VecV.getValueType ().getVectorElementType ();
@@ -1167,7 +1217,7 @@ SDValue VECustomDAG::createConstantTargetMask(VVPWideningInfo WidenInfo) const {
11671217 // we do not want to go through ::ReplaceNodeResults again only to have them
11681218 // widened
11691219 unsigned NativeVectorWidth =
1170- WidenInfo.PackedMode ? PackedWidth : StandardVectorWidth;
1220+ WidenInfo.PackedMode ? PackedVectorWidth : StandardVectorWidth;
11711221
11721222 // Generate a remainder mask for packed operations
11731223 Packing PackFlag = WidenInfo.PackedMode ? Packing::Dense : Packing::Normal;
@@ -1182,7 +1232,7 @@ SDValue VECustomDAG::createConstantTargetMask(VVPWideningInfo WidenInfo) const {
11821232 MaskBits.flip ();
11831233 size_t OddRemainderBitPos = WidenInfo.ActiveVectorLength ;
11841234 MaskBits[OddRemainderBitPos] = false ;
1185- return createConstMask<>(PackedWidth , MaskBits);
1235+ return createConstMask<>(PackedVectorWidth , MaskBits);
11861236 }
11871237}
11881238
0 commit comments