@@ -87,6 +87,11 @@ static cl::opt<bool>
8787 "be combined with a shift"),
8888 cl::init(true));
8989
90+ // TODO: Support more ops
91+ static const unsigned ZvfbfaVPOps[] = {ISD::VP_FNEG, ISD::VP_FABS,
92+ ISD::VP_FCOPYSIGN};
93+ static const unsigned ZvfbfaOps[] = {ISD::FNEG, ISD::FABS, ISD::FCOPYSIGN};
94+
9095RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
9196 const RISCVSubtarget &STI)
9297 : TargetLowering(TM), Subtarget(STI) {
@@ -1208,6 +1213,61 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
12081213 }
12091214 };
12101215
1216+ // Sets common actions for zvfbfa, some of instructions are supported
1217+ // natively so that we don't need to promote them.
1218+ const auto SetZvfbfaActions = [&](MVT VT) {
1219+ setOperationAction({ISD::FP_ROUND, ISD::FP_EXTEND}, VT, Custom);
1220+ setOperationAction({ISD::STRICT_FP_ROUND, ISD::STRICT_FP_EXTEND}, VT,
1221+ Custom);
1222+ setOperationAction({ISD::VP_FP_ROUND, ISD::VP_FP_EXTEND}, VT, Custom);
1223+ setOperationAction({ISD::LRINT, ISD::LLRINT}, VT, Custom);
1224+ setOperationAction({ISD::LROUND, ISD::LLROUND}, VT, Custom);
1225+ setOperationAction({ISD::VP_MERGE, ISD::VP_SELECT, ISD::SELECT}, VT,
1226+ Custom);
1227+ setOperationAction(ISD::SELECT_CC, VT, Expand);
1228+ setOperationAction({ISD::VP_SINT_TO_FP, ISD::VP_UINT_TO_FP}, VT, Custom);
1229+ setOperationAction({ISD::INSERT_VECTOR_ELT, ISD::CONCAT_VECTORS,
1230+ ISD::INSERT_SUBVECTOR, ISD::EXTRACT_SUBVECTOR,
1231+ ISD::VECTOR_DEINTERLEAVE, ISD::VECTOR_INTERLEAVE,
1232+ ISD::VECTOR_REVERSE, ISD::VECTOR_SPLICE,
1233+ ISD::VECTOR_COMPRESS},
1234+ VT, Custom);
1235+ setOperationAction(ISD::EXPERIMENTAL_VP_SPLICE, VT, Custom);
1236+ setOperationAction(ISD::EXPERIMENTAL_VP_REVERSE, VT, Custom);
1237+
1238+ setOperationAction(ISD::FCOPYSIGN, VT, Legal);
1239+ setOperationAction(ZvfbfaVPOps, VT, Custom);
1240+
1241+ MVT EltVT = VT.getVectorElementType();
1242+ if (isTypeLegal(EltVT))
1243+ setOperationAction({ISD::SPLAT_VECTOR, ISD::EXPERIMENTAL_VP_SPLAT,
1244+ ISD::EXTRACT_VECTOR_ELT},
1245+ VT, Custom);
1246+ else
1247+ setOperationAction({ISD::SPLAT_VECTOR, ISD::EXPERIMENTAL_VP_SPLAT},
1248+ EltVT, Custom);
1249+ setOperationAction({ISD::LOAD, ISD::STORE, ISD::MLOAD, ISD::MSTORE,
1250+ ISD::MGATHER, ISD::MSCATTER, ISD::VP_LOAD,
1251+ ISD::VP_STORE, ISD::EXPERIMENTAL_VP_STRIDED_LOAD,
1252+ ISD::EXPERIMENTAL_VP_STRIDED_STORE, ISD::VP_GATHER,
1253+ ISD::VP_SCATTER},
1254+ VT, Custom);
1255+ setOperationAction(ISD::VP_LOAD_FF, VT, Custom);
1256+
1257+ // Expand FP operations that need libcalls.
1258+ setOperationAction(FloatingPointLibCallOps, VT, Expand);
1259+
1260+ // Custom split nxv32[b]f16 since nxv32[b]f32 is not legal.
1261+ if (getLMUL(VT) == RISCVVType::LMUL_8) {
1262+ setOperationAction(ZvfhminZvfbfminPromoteOps, VT, Custom);
1263+ setOperationAction(ZvfhminZvfbfminPromoteVPOps, VT, Custom);
1264+ } else {
1265+ MVT F32VecVT = MVT::getVectorVT(MVT::f32, VT.getVectorElementCount());
1266+ setOperationPromotedToType(ZvfhminZvfbfminPromoteOps, VT, F32VecVT);
1267+ setOperationPromotedToType(ZvfhminZvfbfminPromoteVPOps, VT, F32VecVT);
1268+ }
1269+ };
1270+
12111271 if (Subtarget.hasVInstructionsF16()) {
12121272 for (MVT VT : F16VecVTs) {
12131273 if (!isTypeLegal(VT))
@@ -1222,7 +1282,13 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
12221282 }
12231283 }
12241284
1225- if (Subtarget.hasVInstructionsBF16Minimal()) {
1285+ if (Subtarget.hasVInstructionsBF16()) {
1286+ for (MVT VT : BF16VecVTs) {
1287+ if (!isTypeLegal(VT))
1288+ continue;
1289+ SetZvfbfaActions(VT);
1290+ }
1291+ } else if (Subtarget.hasVInstructionsBF16Minimal()) {
12261292 for (MVT VT : BF16VecVTs) {
12271293 if (!isTypeLegal(VT))
12281294 continue;
@@ -1501,6 +1567,10 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
15011567 // available.
15021568 setOperationAction(ISD::BUILD_VECTOR, MVT::bf16, Custom);
15031569 }
1570+ if (Subtarget.hasStdExtZvfbfa()) {
1571+ setOperationAction(ZvfbfaOps, VT, Custom);
1572+ setOperationAction(ZvfbfaVPOps, VT, Custom);
1573+ }
15041574 setOperationAction(
15051575 {ISD::VP_MERGE, ISD::VP_SELECT, ISD::VSELECT, ISD::SELECT}, VT,
15061576 Custom);
@@ -7245,7 +7315,11 @@ static bool isPromotedOpNeedingSplit(SDValue Op,
72457315 return (Op.getValueType() == MVT::nxv32f16 &&
72467316 (Subtarget.hasVInstructionsF16Minimal() &&
72477317 !Subtarget.hasVInstructionsF16())) ||
7248- Op.getValueType() == MVT::nxv32bf16;
7318+ (Op.getValueType() == MVT::nxv32bf16 &&
7319+ Subtarget.hasVInstructionsBF16Minimal() &&
7320+ (!Subtarget.hasVInstructionsBF16() ||
7321+ (!llvm::is_contained(ZvfbfaOps, Op.getOpcode()) &&
7322+ !llvm::is_contained(ZvfbfaVPOps, Op.getOpcode()))));
72497323}
72507324
72517325static SDValue SplitVectorOp(SDValue Op, SelectionDAG &DAG) {
0 commit comments