Skip to content

Commit 1fa4a74

Browse files
authored
[RISCV] Lower insert_vector_elt on zvfhmin/zvfbfmin (#110221)
This is the dual of #110144, but doesn't handle the case when the scalar type is illegal i.e. no zfhmin/zfbfmin. It looks like softening isn't yet implemented for insert_vector_elt operands and it will crash during type legalization, so I've left that configuration out of the tests.
1 parent f0858bf commit 1fa4a74

File tree

2 files changed

+496
-109
lines changed

2 files changed

+496
-109
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,9 +1076,10 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
10761076
setOperationAction({ISD::SINT_TO_FP, ISD::UINT_TO_FP, ISD::VP_SINT_TO_FP,
10771077
ISD::VP_UINT_TO_FP},
10781078
VT, Custom);
1079-
setOperationAction({ISD::CONCAT_VECTORS, ISD::INSERT_SUBVECTOR,
1080-
ISD::EXTRACT_SUBVECTOR, ISD::VECTOR_DEINTERLEAVE,
1081-
ISD::VECTOR_INTERLEAVE, ISD::VECTOR_REVERSE},
1079+
setOperationAction({ISD::INSERT_VECTOR_ELT, ISD::CONCAT_VECTORS,
1080+
ISD::INSERT_SUBVECTOR, ISD::EXTRACT_SUBVECTOR,
1081+
ISD::VECTOR_DEINTERLEAVE, ISD::VECTOR_INTERLEAVE,
1082+
ISD::VECTOR_REVERSE},
10821083
VT, Custom);
10831084
MVT EltVT = VT.getVectorElementType();
10841085
if (isTypeLegal(EltVT))
@@ -8756,8 +8757,10 @@ SDValue RISCVTargetLowering::lowerINSERT_VECTOR_ELT(SDValue Op,
87568757
SelectionDAG &DAG) const {
87578758
SDLoc DL(Op);
87588759
MVT VecVT = Op.getSimpleValueType();
8760+
MVT XLenVT = Subtarget.getXLenVT();
87598761
SDValue Vec = Op.getOperand(0);
87608762
SDValue Val = Op.getOperand(1);
8763+
MVT ValVT = Val.getSimpleValueType();
87618764
SDValue Idx = Op.getOperand(2);
87628765

87638766
if (VecVT.getVectorElementType() == MVT::i1) {
@@ -8769,6 +8772,16 @@ SDValue RISCVTargetLowering::lowerINSERT_VECTOR_ELT(SDValue Op,
87698772
return DAG.getNode(ISD::TRUNCATE, DL, VecVT, Vec);
87708773
}
87718774

8775+
if ((ValVT == MVT::f16 && !Subtarget.hasVInstructionsF16()) ||
8776+
ValVT == MVT::bf16) {
8777+
// If we don't have vfmv.s.f for f16/bf16, use fmv.x.h first.
8778+
MVT IntVT = VecVT.changeTypeToInteger();
8779+
SDValue IntInsert = DAG.getNode(
8780+
ISD::INSERT_VECTOR_ELT, DL, IntVT, DAG.getBitcast(IntVT, Vec),
8781+
DAG.getNode(RISCVISD::FMV_X_ANYEXTH, DL, XLenVT, Val), Idx);
8782+
return DAG.getBitcast(VecVT, IntInsert);
8783+
}
8784+
87728785
MVT ContainerVT = VecVT;
87738786
// If the operand is a fixed-length vector, convert to a scalable one.
87748787
if (VecVT.isFixedLengthVector()) {
@@ -8812,8 +8825,6 @@ SDValue RISCVTargetLowering::lowerINSERT_VECTOR_ELT(SDValue Op,
88128825
AlignedIdx);
88138826
}
88148827

8815-
MVT XLenVT = Subtarget.getXLenVT();
8816-
88178828
bool IsLegalInsert = Subtarget.is64Bit() || Val.getValueType() != MVT::i64;
88188829
// Even i64-element vectors on RV32 can be lowered without scalar
88198830
// legalization if the most-significant 32 bits of the value are not affected

0 commit comments

Comments
 (0)