@@ -506,8 +506,9 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
506506 VT, Expand);
507507 }
508508
509- setOperationAction ({ISD::VP_FPTOSI, ISD::VP_FPTOUI, ISD::VP_TRUNC}, VT,
510- Custom);
509+ setOperationAction (
510+ {ISD::VP_FPTOSI, ISD::VP_FPTOUI, ISD::VP_TRUNC, ISD::VP_SETCC}, VT,
511+ Custom);
511512 }
512513
513514 for (MVT VT : IntVecVTs) {
@@ -3497,6 +3498,8 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op,
34973498 case ISD::VP_UITOFP:
34983499 return lowerVPFPIntConvOp (Op, DAG, RISCVISD::UINT_TO_FP_VL);
34993500 case ISD::VP_SETCC:
3501+ if (Op.getOperand (0 ).getSimpleValueType ().getVectorElementType () == MVT::i1)
3502+ return lowerVPSetCCMaskOp (Op, DAG);
35003503 return lowerVPOp (Op, DAG, RISCVISD::SETCC_VL);
35013504 }
35023505}
@@ -6099,6 +6102,85 @@ SDValue RISCVTargetLowering::lowerVPExtMaskOp(SDValue Op,
60996102 return convertFromScalableVector (VT, Result, DAG, Subtarget);
61006103}
61016104
6105+ SDValue RISCVTargetLowering::lowerVPSetCCMaskOp (SDValue Op,
6106+ SelectionDAG &DAG) const {
6107+ SDLoc DL (Op);
6108+ MVT VT = Op.getSimpleValueType ();
6109+
6110+ SDValue Op1 = Op.getOperand (0 );
6111+ SDValue Op2 = Op.getOperand (1 );
6112+ ISD::CondCode Condition = cast<CondCodeSDNode>(Op.getOperand (2 ))->get ();
6113+ // NOTE: Mask is dropped.
6114+ SDValue VL = Op.getOperand (4 );
6115+
6116+ MVT ContainerVT = VT;
6117+ if (VT.isFixedLengthVector ()) {
6118+ ContainerVT = getContainerForFixedLengthVector (VT);
6119+ Op1 = convertToScalableVector (ContainerVT, Op1, DAG, Subtarget);
6120+ Op2 = convertToScalableVector (ContainerVT, Op2, DAG, Subtarget);
6121+ }
6122+
6123+ SDValue Result;
6124+ SDValue AllOneMask = DAG.getNode (RISCVISD::VMSET_VL, DL, ContainerVT, VL);
6125+
6126+ switch (Condition) {
6127+ default :
6128+ break ;
6129+ // X != Y --> (X^Y)
6130+ case ISD::SETNE:
6131+ Result = DAG.getNode (RISCVISD::VMXOR_VL, DL, ContainerVT, Op1, Op2, VL);
6132+ break ;
6133+ // X == Y --> ~(X^Y)
6134+ case ISD::SETEQ: {
6135+ SDValue Temp =
6136+ DAG.getNode (RISCVISD::VMXOR_VL, DL, ContainerVT, Op1, Op2, VL);
6137+ Result =
6138+ DAG.getNode (RISCVISD::VMXOR_VL, DL, ContainerVT, Temp, AllOneMask, VL);
6139+ break ;
6140+ }
6141+ // X >s Y --> X == 0 & Y == 1 --> ~X & Y
6142+ // X <u Y --> X == 0 & Y == 1 --> ~X & Y
6143+ case ISD::SETGT:
6144+ case ISD::SETULT: {
6145+ SDValue Temp =
6146+ DAG.getNode (RISCVISD::VMXOR_VL, DL, ContainerVT, Op1, AllOneMask, VL);
6147+ Result = DAG.getNode (RISCVISD::VMAND_VL, DL, ContainerVT, Temp, Op2, VL);
6148+ break ;
6149+ }
6150+ // X <s Y --> X == 1 & Y == 0 --> ~Y & X
6151+ // X >u Y --> X == 1 & Y == 0 --> ~Y & X
6152+ case ISD::SETLT:
6153+ case ISD::SETUGT: {
6154+ SDValue Temp =
6155+ DAG.getNode (RISCVISD::VMXOR_VL, DL, ContainerVT, Op2, AllOneMask, VL);
6156+ Result = DAG.getNode (RISCVISD::VMAND_VL, DL, ContainerVT, Op1, Temp, VL);
6157+ break ;
6158+ }
6159+ // X >=s Y --> X == 0 | Y == 1 --> ~X | Y
6160+ // X <=u Y --> X == 0 | Y == 1 --> ~X | Y
6161+ case ISD::SETGE:
6162+ case ISD::SETULE: {
6163+ SDValue Temp =
6164+ DAG.getNode (RISCVISD::VMXOR_VL, DL, ContainerVT, Op1, AllOneMask, VL);
6165+ Result = DAG.getNode (RISCVISD::VMXOR_VL, DL, ContainerVT, Temp, Op2, VL);
6166+ break ;
6167+ }
6168+ // X <=s Y --> X == 1 | Y == 0 --> ~Y | X
6169+ // X >=u Y --> X == 1 | Y == 0 --> ~Y | X
6170+ case ISD::SETLE:
6171+ case ISD::SETUGE: {
6172+ SDValue Temp =
6173+ DAG.getNode (RISCVISD::VMXOR_VL, DL, ContainerVT, Op2, AllOneMask, VL);
6174+ Result = DAG.getNode (RISCVISD::VMXOR_VL, DL, ContainerVT, Temp, Op1, VL);
6175+ break ;
6176+ }
6177+ }
6178+
6179+ if (!VT.isFixedLengthVector ())
6180+ return Result;
6181+ return convertFromScalableVector (VT, Result, DAG, Subtarget);
6182+ }
6183+
61026184// Lower Floating-Point/Integer Type-Convert VP SDNodes
61036185SDValue RISCVTargetLowering::lowerVPFPIntConvOp (SDValue Op, SelectionDAG &DAG,
61046186 unsigned RISCVISDOpc) const {
0 commit comments