@@ -968,6 +968,28 @@ static SDValue checkIntrinsicImmArg(SDValue Op, unsigned ImmOp,
968
968
return SDValue ();
969
969
}
970
970
971
+ static SDValue checkAndModifyXVPERMI_QIntrinsicImmArg (SDValue Op,
972
+ SelectionDAG &DAG) {
973
+ SDValue Op3 = Op->getOperand (3 );
974
+ uint64_t Imm = Op3->getAsZExtVal ();
975
+ // Check the range of ImmArg.
976
+ if (!isUInt<8 >(Imm)) {
977
+ DAG.getContext ()->emitError (Op->getOperationName (0 ) +
978
+ " : argument out of range." );
979
+ return DAG.getNode (ISD::UNDEF, SDLoc (Op), Op.getValueType ());
980
+ }
981
+
982
+ // For instruction xvpermi.q, only [1:0] and [5:4] bits of operands[3]
983
+ // are used. The unused bits in operands[3] need to be set to 0 to avoid
984
+ // causing undefined behavior on LA464.
985
+ if ((Imm & 0x33 ) != Imm) {
986
+ Op3 = DAG.getTargetConstant (Imm & 0x33 , SDLoc (Op), Op3.getValueType ());
987
+ DAG.UpdateNodeOperands (Op.getNode (), Op->getOperand (0 ), Op->getOperand (1 ),
988
+ Op->getOperand (2 ), Op3);
989
+ }
990
+ return SDValue ();
991
+ }
992
+
971
993
SDValue
972
994
LoongArchTargetLowering::lowerINTRINSIC_WO_CHAIN (SDValue Op,
973
995
SelectionDAG &DAG) const {
@@ -1225,13 +1247,14 @@ LoongArchTargetLowering::lowerINTRINSIC_WO_CHAIN(SDValue Op,
1225
1247
case Intrinsic::loongarch_lsx_vextrins_d:
1226
1248
case Intrinsic::loongarch_lasx_xvshuf4i_d:
1227
1249
case Intrinsic::loongarch_lasx_xvpermi_w:
1228
- case Intrinsic::loongarch_lasx_xvpermi_q:
1229
1250
case Intrinsic::loongarch_lasx_xvbitseli_b:
1230
1251
case Intrinsic::loongarch_lasx_xvextrins_b:
1231
1252
case Intrinsic::loongarch_lasx_xvextrins_h:
1232
1253
case Intrinsic::loongarch_lasx_xvextrins_w:
1233
1254
case Intrinsic::loongarch_lasx_xvextrins_d:
1234
1255
return checkIntrinsicImmArg<8 >(Op, 3 , DAG);
1256
+ case Intrinsic::loongarch_lasx_xvpermi_q:
1257
+ return checkAndModifyXVPERMI_QIntrinsicImmArg (Op, DAG);
1235
1258
case Intrinsic::loongarch_lsx_vrepli_b:
1236
1259
case Intrinsic::loongarch_lsx_vrepli_h:
1237
1260
case Intrinsic::loongarch_lsx_vrepli_w:
0 commit comments