@@ -9723,21 +9723,6 @@ SDValue RISCVTargetLowering::lowerVPREDUCE(SDValue Op,
9723
9723
Vec, Mask, VL, DL, DAG, Subtarget);
9724
9724
}
9725
9725
9726
- /// Returns true if \p LHS is known to be equal to \p RHS, taking into account
9727
- /// if VLEN is exactly known by \p Subtarget and thus vscale when handling
9728
- /// scalable quantities.
9729
- static bool isKnownEQ(ElementCount LHS, ElementCount RHS,
9730
- const RISCVSubtarget &Subtarget) {
9731
- if (auto VLen = Subtarget.getRealVLen()) {
9732
- const unsigned Vscale = *VLen / RISCV::RVVBitsPerBlock;
9733
- if (LHS.isScalable())
9734
- LHS = ElementCount::getFixed(LHS.getKnownMinValue() * Vscale);
9735
- if (RHS.isScalable())
9736
- RHS = ElementCount::getFixed(RHS.getKnownMinValue() * Vscale);
9737
- }
9738
- return LHS == RHS;
9739
- }
9740
-
9741
9726
SDValue RISCVTargetLowering::lowerINSERT_SUBVECTOR(SDValue Op,
9742
9727
SelectionDAG &DAG) const {
9743
9728
SDValue Vec = Op.getOperand(0);
@@ -9875,29 +9860,25 @@ SDValue RISCVTargetLowering::lowerINSERT_SUBVECTOR(SDValue Op,
9875
9860
RemIdx = ElementCount::getScalable(Decompose.second);
9876
9861
}
9877
9862
9878
- RISCVII::VLMUL SubVecLMUL = RISCVTargetLowering::getLMUL(ContainerSubVecVT);
9879
- bool IsSubVecPartReg = SubVecLMUL == RISCVII::VLMUL::LMUL_F2 ||
9880
- SubVecLMUL == RISCVII::VLMUL::LMUL_F4 ||
9881
- SubVecLMUL == RISCVII::VLMUL::LMUL_F8;
9882
- bool AlignedToVecReg = !IsSubVecPartReg;
9883
- if (SubVecVT.isFixedLengthVector())
9884
- AlignedToVecReg &= SubVecVT.getSizeInBits() ==
9885
- ContainerSubVecVT.getSizeInBits().getKnownMinValue() *
9886
- (*VLen / RISCV::RVVBitsPerBlock);
9863
+ TypeSize VecRegSize = TypeSize::getScalable(RISCV::RVVBitsPerBlock);
9864
+ bool ExactlyVecRegSized =
9865
+ Subtarget.expandVScale(SubVecVT.getSizeInBits())
9866
+ .isKnownMultipleOf(Subtarget.expandVScale(VecRegSize));
9887
9867
9888
9868
// 1. If the Idx has been completely eliminated and this subvector's size is
9889
9869
// a vector register or a multiple thereof, or the surrounding elements are
9890
9870
// undef, then this is a subvector insert which naturally aligns to a vector
9891
9871
// register. These can easily be handled using subregister manipulation.
9892
- // 2. If the subvector isn't exactly aligned to a vector register group, then
9893
- // the insertion must preserve the undisturbed elements of the register. We do
9894
- // this by lowering to an EXTRACT_SUBVECTOR grabbing the nearest LMUL=1 vector
9895
- // type (which resolves to a subregister copy), performing a VSLIDEUP to place
9896
- // the subvector within the vector register, and an INSERT_SUBVECTOR of that
9897
- // LMUL=1 type back into the larger vector (resolving to another subregister
9898
- // operation). See below for how our VSLIDEUP works. We go via a LMUL=1 type
9899
- // to avoid allocating a large register group to hold our subvector.
9900
- if (RemIdx.isZero() && (AlignedToVecReg || Vec.isUndef())) {
9872
+ // 2. If the subvector isn't an exact multiple of a valid register group size,
9873
+ // then the insertion must preserve the undisturbed elements of the register.
9874
+ // We do this by lowering to an EXTRACT_SUBVECTOR grabbing the nearest LMUL=1
9875
+ // vector type (which resolves to a subregister copy), performing a VSLIDEUP
9876
+ // to place the subvector within the vector register, and an INSERT_SUBVECTOR
9877
+ // of that LMUL=1 type back into the larger vector (resolving to another
9878
+ // subregister operation). See below for how our VSLIDEUP works. We go via a
9879
+ // LMUL=1 type to avoid allocating a large register group to hold our
9880
+ // subvector.
9881
+ if (RemIdx.isZero() && (ExactlyVecRegSized || Vec.isUndef())) {
9901
9882
if (SubVecVT.isFixedLengthVector()) {
9902
9883
// We may get NoSubRegister if inserting at index 0 and the subvec
9903
9884
// container is the same as the vector, e.g. vec=v4i32,subvec=v4i32,idx=0
@@ -9944,7 +9925,8 @@ SDValue RISCVTargetLowering::lowerINSERT_SUBVECTOR(SDValue Op,
9944
9925
9945
9926
// Use tail agnostic policy if we're inserting over InterSubVT's tail.
9946
9927
unsigned Policy = RISCVII::TAIL_UNDISTURBED_MASK_UNDISTURBED;
9947
- if (isKnownEQ(EndIndex, InterSubVT.getVectorElementCount(), Subtarget))
9928
+ if (Subtarget.expandVScale(EndIndex) ==
9929
+ Subtarget.expandVScale(InterSubVT.getVectorElementCount()))
9948
9930
Policy = RISCVII::TAIL_AGNOSTIC;
9949
9931
9950
9932
// If we're inserting into the lowest elements, use a tail undisturbed
0 commit comments