@@ -1063,6 +1063,45 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
1063
1063
}
1064
1064
};
1065
1065
1066
+ // Sets common actions for f16 and bf16 for when there's only
1067
+ // zvfhmin/zvfbfmin and we need to promote to f32 for most operations.
1068
+ const auto SetCommonPromoteToF32Actions = [&](MVT VT) {
1069
+ setOperationAction({ISD::FP_ROUND, ISD::FP_EXTEND}, VT, Custom);
1070
+ setOperationAction({ISD::STRICT_FP_ROUND, ISD::STRICT_FP_EXTEND}, VT,
1071
+ Custom);
1072
+ setOperationAction({ISD::VP_FP_ROUND, ISD::VP_FP_EXTEND}, VT, Custom);
1073
+ setOperationAction({ISD::VP_MERGE, ISD::VP_SELECT, ISD::SELECT}, VT,
1074
+ Custom);
1075
+ setOperationAction(ISD::SELECT_CC, VT, Expand);
1076
+ setOperationAction({ISD::SINT_TO_FP, ISD::UINT_TO_FP, ISD::VP_SINT_TO_FP,
1077
+ ISD::VP_UINT_TO_FP},
1078
+ VT, Custom);
1079
+ setOperationAction({ISD::CONCAT_VECTORS, ISD::INSERT_SUBVECTOR,
1080
+ ISD::EXTRACT_SUBVECTOR, ISD::VECTOR_INTERLEAVE,
1081
+ ISD::VECTOR_DEINTERLEAVE},
1082
+ VT, Custom);
1083
+ MVT EltVT = VT.getVectorElementType();
1084
+ if (isTypeLegal(EltVT))
1085
+ setOperationAction(ISD::SPLAT_VECTOR, VT, Custom);
1086
+ else
1087
+ setOperationAction(ISD::SPLAT_VECTOR, EltVT, Custom);
1088
+ setOperationAction({ISD::LOAD, ISD::STORE}, VT, Custom);
1089
+
1090
+ setOperationAction(ISD::FNEG, VT, Expand);
1091
+ setOperationAction(ISD::FABS, VT, Expand);
1092
+ setOperationAction(ISD::FCOPYSIGN, VT, Expand);
1093
+
1094
+ // Custom split nxv32[b]f16 since nxv32[b]f32 is not legal.
1095
+ if (getLMUL(VT) == RISCVII::VLMUL::LMUL_8) {
1096
+ setOperationAction(ZvfhminZvfbfminPromoteOps, VT, Custom);
1097
+ setOperationAction(ZvfhminZvfbfminPromoteVPOps, VT, Custom);
1098
+ } else {
1099
+ MVT F32VecVT = MVT::getVectorVT(MVT::f32, VT.getVectorElementCount());
1100
+ setOperationPromotedToType(ZvfhminZvfbfminPromoteOps, VT, F32VecVT);
1101
+ setOperationPromotedToType(ZvfhminZvfbfminPromoteVPOps, VT, F32VecVT);
1102
+ }
1103
+ };
1104
+
1066
1105
if (Subtarget.hasVInstructionsF16()) {
1067
1106
for (MVT VT : F16VecVTs) {
1068
1107
if (!isTypeLegal(VT))
@@ -1073,83 +1112,15 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
1073
1112
for (MVT VT : F16VecVTs) {
1074
1113
if (!isTypeLegal(VT))
1075
1114
continue;
1076
- setOperationAction({ISD::FP_ROUND, ISD::FP_EXTEND}, VT, Custom);
1077
- setOperationAction({ISD::STRICT_FP_ROUND, ISD::STRICT_FP_EXTEND}, VT,
1078
- Custom);
1079
- setOperationAction({ISD::VP_FP_ROUND, ISD::VP_FP_EXTEND}, VT, Custom);
1080
- setOperationAction({ISD::VP_MERGE, ISD::VP_SELECT, ISD::SELECT}, VT,
1081
- Custom);
1082
- setOperationAction(ISD::SELECT_CC, VT, Expand);
1083
- setOperationAction({ISD::SINT_TO_FP, ISD::UINT_TO_FP,
1084
- ISD::VP_SINT_TO_FP, ISD::VP_UINT_TO_FP},
1085
- VT, Custom);
1086
- setOperationAction({ISD::CONCAT_VECTORS, ISD::INSERT_SUBVECTOR,
1087
- ISD::EXTRACT_SUBVECTOR, ISD::VECTOR_INTERLEAVE,
1088
- ISD::VECTOR_DEINTERLEAVE},
1089
- VT, Custom);
1090
- if (Subtarget.hasStdExtZfhmin())
1091
- setOperationAction(ISD::SPLAT_VECTOR, VT, Custom);
1092
- else
1093
- setOperationAction(ISD::SPLAT_VECTOR, MVT::f16, Custom);
1094
- // load/store
1095
- setOperationAction({ISD::LOAD, ISD::STORE}, VT, Custom);
1096
-
1097
- setOperationAction(ISD::FNEG, VT, Expand);
1098
- setOperationAction(ISD::FABS, VT, Expand);
1099
- setOperationAction(ISD::FCOPYSIGN, VT, Expand);
1100
-
1101
- // Custom split nxv32f16 since nxv32f32 is not legal.
1102
- if (VT == MVT::nxv32f16) {
1103
- setOperationAction(ZvfhminZvfbfminPromoteOps, VT, Custom);
1104
- setOperationAction(ZvfhminZvfbfminPromoteVPOps, VT, Custom);
1105
- continue;
1106
- }
1107
- // Add more promote ops.
1108
- MVT F32VecVT = MVT::getVectorVT(MVT::f32, VT.getVectorElementCount());
1109
- setOperationPromotedToType(ZvfhminZvfbfminPromoteOps, VT, F32VecVT);
1110
- setOperationPromotedToType(ZvfhminZvfbfminPromoteVPOps, VT, F32VecVT);
1115
+ SetCommonPromoteToF32Actions(VT);
1111
1116
}
1112
1117
}
1113
1118
1114
- // TODO: merge with zvfhmin
1115
1119
if (Subtarget.hasVInstructionsBF16Minimal()) {
1116
1120
for (MVT VT : BF16VecVTs) {
1117
1121
if (!isTypeLegal(VT))
1118
1122
continue;
1119
- setOperationAction({ISD::FP_ROUND, ISD::FP_EXTEND}, VT, Custom);
1120
- setOperationAction({ISD::STRICT_FP_ROUND, ISD::STRICT_FP_EXTEND}, VT,
1121
- Custom);
1122
- setOperationAction({ISD::VP_FP_ROUND, ISD::VP_FP_EXTEND}, VT, Custom);
1123
- setOperationAction({ISD::VP_MERGE, ISD::VP_SELECT, ISD::SELECT}, VT,
1124
- Custom);
1125
- setOperationAction(ISD::SELECT_CC, VT, Expand);
1126
- setOperationAction({ISD::SINT_TO_FP, ISD::UINT_TO_FP,
1127
- ISD::VP_SINT_TO_FP, ISD::VP_UINT_TO_FP},
1128
- VT, Custom);
1129
- setOperationAction({ISD::CONCAT_VECTORS, ISD::INSERT_SUBVECTOR,
1130
- ISD::EXTRACT_SUBVECTOR, ISD::VECTOR_INTERLEAVE,
1131
- ISD::VECTOR_DEINTERLEAVE},
1132
- VT, Custom);
1133
- if (Subtarget.hasStdExtZfbfmin())
1134
- setOperationAction(ISD::SPLAT_VECTOR, VT, Custom);
1135
- else
1136
- setOperationAction(ISD::SPLAT_VECTOR, MVT::bf16, Custom);
1137
- setOperationAction({ISD::LOAD, ISD::STORE}, VT, Custom);
1138
-
1139
- setOperationAction(ISD::FNEG, VT, Expand);
1140
- setOperationAction(ISD::FABS, VT, Expand);
1141
- setOperationAction(ISD::FCOPYSIGN, VT, Expand);
1142
-
1143
- // Custom split nxv32f16 since nxv32f32 is not legal.
1144
- if (VT == MVT::nxv32bf16) {
1145
- setOperationAction(ZvfhminZvfbfminPromoteOps, VT, Custom);
1146
- setOperationAction(ZvfhminZvfbfminPromoteVPOps, VT, Custom);
1147
- continue;
1148
- }
1149
- // Add more promote ops.
1150
- MVT F32VecVT = MVT::getVectorVT(MVT::f32, VT.getVectorElementCount());
1151
- setOperationPromotedToType(ZvfhminZvfbfminPromoteOps, VT, F32VecVT);
1152
- setOperationPromotedToType(ZvfhminZvfbfminPromoteVPOps, VT, F32VecVT);
1123
+ SetCommonPromoteToF32Actions(VT);
1153
1124
}
1154
1125
}
1155
1126
0 commit comments