Skip to content

Commit a8e525d

Browse files
committed
[RISCV] Lower insert_vector_elt on zvfhmin/zvfbfmin
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 30f58ab commit a8e525d

File tree

2 files changed

+497
-109
lines changed

2 files changed

+497
-109
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 17 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,17 @@ 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, insert into fmv.x.h first
8778+
MVT IntVT = VecVT.changeTypeToInteger();
8779+
// SDValue IntVal = DAG.getBitcast(IntVT.getVectorElementType(), Val);
8780+
SDValue IntInsert = DAG.getNode(
8781+
ISD::INSERT_VECTOR_ELT, DL, IntVT, DAG.getBitcast(IntVT, Vec),
8782+
DAG.getNode(RISCVISD::FMV_X_ANYEXTH, DL, XLenVT, Val), Idx);
8783+
return DAG.getBitcast(VecVT, IntInsert);
8784+
}
8785+
87728786
MVT ContainerVT = VecVT;
87738787
// If the operand is a fixed-length vector, convert to a scalable one.
87748788
if (VecVT.isFixedLengthVector()) {
@@ -8812,8 +8826,6 @@ SDValue RISCVTargetLowering::lowerINSERT_VECTOR_ELT(SDValue Op,
88128826
AlignedIdx);
88138827
}
88148828

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

0 commit comments

Comments
 (0)