@@ -271,6 +271,7 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
271271 setCondCodeAction (
272272 {ISD::SETNE, ISD::SETGE, ISD::SETGT, ISD::SETUGE, ISD::SETUGT}, VT,
273273 Expand);
274+ setOperationAction (ISD::SCALAR_TO_VECTOR, VT, Custom);
274275 }
275276 for (MVT VT : {MVT::v16i8, MVT::v8i16, MVT::v4i32})
276277 setOperationAction (ISD::BITREVERSE, VT, Custom);
@@ -289,6 +290,7 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
289290 setCondCodeAction ({ISD::SETGE, ISD::SETGT, ISD::SETOGE, ISD::SETOGT,
290291 ISD::SETUGE, ISD::SETUGT},
291292 VT, Expand);
293+ setOperationAction (ISD::SCALAR_TO_VECTOR, VT, Legal);
292294 }
293295 setOperationAction (ISD::CTPOP, GRLenVT, Legal);
294296 setOperationAction (ISD::FCEIL, {MVT::f32 , MVT::f64 }, Legal);
@@ -327,6 +329,7 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
327329 setCondCodeAction (
328330 {ISD::SETNE, ISD::SETGE, ISD::SETGT, ISD::SETUGE, ISD::SETUGT}, VT,
329331 Expand);
332+ setOperationAction (ISD::SCALAR_TO_VECTOR, VT, Custom);
330333 }
331334 for (MVT VT : {MVT::v32i8, MVT::v16i16, MVT::v8i32})
332335 setOperationAction (ISD::BITREVERSE, VT, Custom);
@@ -345,6 +348,7 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
345348 setCondCodeAction ({ISD::SETGE, ISD::SETGT, ISD::SETOGE, ISD::SETOGT,
346349 ISD::SETUGE, ISD::SETUGT},
347350 VT, Expand);
351+ setOperationAction (ISD::SCALAR_TO_VECTOR, VT, Legal);
348352 }
349353 }
350354
@@ -448,10 +452,25 @@ SDValue LoongArchTargetLowering::LowerOperation(SDValue Op,
448452 return lowerVECTOR_SHUFFLE (Op, DAG);
449453 case ISD::BITREVERSE:
450454 return lowerBITREVERSE (Op, DAG);
455+ case ISD::SCALAR_TO_VECTOR:
456+ return lowerSCALAR_TO_VECTOR (Op, DAG);
451457 }
452458 return SDValue ();
453459}
454460
461+ SDValue
462+ LoongArchTargetLowering::lowerSCALAR_TO_VECTOR (SDValue Op,
463+ SelectionDAG &DAG) const {
464+ SDLoc DL (Op);
465+ MVT OpVT = Op.getSimpleValueType ();
466+
467+ SDValue Vector = DAG.getUNDEF (OpVT);
468+ SDValue Val = Op.getOperand (0 );
469+ SDValue Idx = DAG.getConstant (0 , DL, Subtarget.getGRLenVT ());
470+
471+ return DAG.getNode (ISD::INSERT_VECTOR_ELT, DL, OpVT, Vector, Val, Idx);
472+ }
473+
455474SDValue LoongArchTargetLowering::lowerBITREVERSE (SDValue Op,
456475 SelectionDAG &DAG) const {
457476 EVT ResTy = Op->getValueType (0 );
0 commit comments