diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -7438,31 +7438,34 @@ DAG.getConstant(AlignedIdx, DL, XLenVT)); } - SDValue SlideupAmt = + SDValue SlideAmt = DAG.getVScale(DL, XLenVT, APInt(XLenVT.getSizeInBits(), RemIdx)); auto [Mask, VL] = getDefaultScalableVLOps(VecVT, DL, DAG, Subtarget); // Construct the vector length corresponding to RemIdx + length(SubVecVT). VL = computeVLMax(SubVecVT, DL, DAG); - VL = DAG.getNode(ISD::ADD, DL, XLenVT, SlideupAmt, VL); + VL = DAG.getNode(ISD::ADD, DL, XLenVT, SlideAmt, VL); SubVec = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, InterSubVT, DAG.getUNDEF(InterSubVT), SubVec, DAG.getConstant(0, DL, XLenVT)); - SDValue Slideup = getVSlideup(DAG, Subtarget, DL, InterSubVT, AlignedExtract, - SubVec, SlideupAmt, Mask, VL); + SDValue Slide = + (RemIdx == 0) ? getVSlidedown(DAG, Subtarget, DL, InterSubVT, + AlignedExtract, SubVec, SlideAmt, Mask, VL) + : getVSlideup(DAG, Subtarget, DL, InterSubVT, + AlignedExtract, SubVec, SlideAmt, Mask, VL); // If required, insert this subvector back into the correct vector register. // This should resolve to an INSERT_SUBREG instruction. if (VecVT.bitsGT(InterSubVT)) - Slideup = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, VecVT, Vec, Slideup, - DAG.getConstant(AlignedIdx, DL, XLenVT)); + Slide = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, VecVT, Vec, Slide, + DAG.getConstant(AlignedIdx, DL, XLenVT)); // We might have bitcast from a mask type: cast back to the original type if // required. - return DAG.getBitcast(Op.getSimpleValueType(), Slideup); + return DAG.getBitcast(Op.getSimpleValueType(), Slide); } SDValue RISCVTargetLowering::lowerEXTRACT_SUBVECTOR(SDValue Op, diff --git a/llvm/test/CodeGen/RISCV/rvv/extract-subvector.ll b/llvm/test/CodeGen/RISCV/rvv/extract-subvector.ll --- a/llvm/test/CodeGen/RISCV/rvv/extract-subvector.ll +++ b/llvm/test/CodeGen/RISCV/rvv/extract-subvector.ll @@ -473,7 +473,7 @@ ; CHECK-NEXT: vslidedown.vx v11, v10, a0 ; CHECK-NEXT: vslidedown.vx v8, v9, a0 ; CHECK-NEXT: vsetvli zero, a0, e16, m1, tu, ma -; CHECK-NEXT: vslideup.vi v9, v11, 0 +; CHECK-NEXT: vslidedown.vi v9, v11, 0 ; CHECK-NEXT: add a1, a0, a0 ; CHECK-NEXT: vsetvli zero, a1, e16, m1, tu, ma ; CHECK-NEXT: vslideup.vx v8, v10, a0 diff --git a/llvm/test/CodeGen/RISCV/rvv/insert-subvector.ll b/llvm/test/CodeGen/RISCV/rvv/insert-subvector.ll --- a/llvm/test/CodeGen/RISCV/rvv/insert-subvector.ll +++ b/llvm/test/CodeGen/RISCV/rvv/insert-subvector.ll @@ -62,7 +62,7 @@ ; CHECK-NEXT: csrr a0, vlenb ; CHECK-NEXT: srli a0, a0, 3 ; CHECK-NEXT: vsetvli zero, a0, e8, mf2, tu, ma -; CHECK-NEXT: vslideup.vi v8, v9, 0 +; CHECK-NEXT: vslidedown.vi v8, v9, 0 ; CHECK-NEXT: ret %v = call @llvm.vector.insert.nxv1i8.nxv4i8( %vec, %subvec, i64 0) ret %v @@ -215,7 +215,7 @@ ; CHECK-NEXT: csrr a0, vlenb ; CHECK-NEXT: srli a0, a0, 3 ; CHECK-NEXT: vsetvli zero, a0, e32, m1, tu, ma -; CHECK-NEXT: vslideup.vi v8, v16, 0 +; CHECK-NEXT: vslidedown.vi v8, v16, 0 ; CHECK-NEXT: ret %v = call @llvm.vector.insert.nxv1i32.nxv16i32( %vec, %subvec, i64 0) ret %v @@ -240,7 +240,7 @@ ; CHECK-NEXT: csrr a0, vlenb ; CHECK-NEXT: srli a0, a0, 3 ; CHECK-NEXT: vsetvli zero, a0, e32, m1, tu, ma -; CHECK-NEXT: vslideup.vi v11, v16, 0 +; CHECK-NEXT: vslidedown.vi v11, v16, 0 ; CHECK-NEXT: ret %v = call @llvm.vector.insert.nxv1i32.nxv16i32( %vec, %subvec, i64 6) ret %v @@ -252,7 +252,7 @@ ; CHECK-NEXT: csrr a0, vlenb ; CHECK-NEXT: srli a0, a0, 3 ; CHECK-NEXT: vsetvli zero, a0, e8, m1, tu, ma -; CHECK-NEXT: vslideup.vi v8, v10, 0 +; CHECK-NEXT: vslidedown.vi v8, v10, 0 ; CHECK-NEXT: ret %v = call @llvm.vector.insert.nxv1i8.nxv16i8( %vec, %subvec, i64 0) ret %v @@ -332,7 +332,7 @@ ; CHECK-NEXT: csrr a0, vlenb ; CHECK-NEXT: srli a0, a0, 2 ; CHECK-NEXT: vsetvli zero, a0, e16, m1, tu, ma -; CHECK-NEXT: vslideup.vi v8, v16, 0 +; CHECK-NEXT: vslidedown.vi v8, v16, 0 ; CHECK-NEXT: ret %v = call @llvm.vector.insert.nxv2f16.nxv32f16( %vec, %subvec, i64 0) ret %v @@ -392,7 +392,7 @@ ; CHECK-NEXT: csrr a0, vlenb ; CHECK-NEXT: srli a0, a0, 3 ; CHECK-NEXT: vsetvli zero, a0, e8, mf2, tu, ma -; CHECK-NEXT: vslideup.vi v0, v8, 0 +; CHECK-NEXT: vslidedown.vi v0, v8, 0 ; CHECK-NEXT: ret %vec = call @llvm.vector.insert.nxv8i1.nxv32i1( %v, %sv, i64 0) ret %vec @@ -424,7 +424,7 @@ ; CHECK-NEXT: csrr a0, vlenb ; CHECK-NEXT: srli a0, a0, 3 ; CHECK-NEXT: vsetvli zero, a0, e8, mf2, tu, ma -; CHECK-NEXT: vslideup.vi v9, v8, 0 +; CHECK-NEXT: vslidedown.vi v9, v8, 0 ; CHECK-NEXT: vsetvli a0, zero, e8, mf2, ta, ma ; CHECK-NEXT: vmsne.vi v0, v9, 0 ; CHECK-NEXT: ret diff --git a/llvm/test/CodeGen/RISCV/rvv/vreductions-fp-sdnode.ll b/llvm/test/CodeGen/RISCV/rvv/vreductions-fp-sdnode.ll --- a/llvm/test/CodeGen/RISCV/rvv/vreductions-fp-sdnode.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vreductions-fp-sdnode.ll @@ -1033,7 +1033,7 @@ ; CHECK-NEXT: vsetvli zero, a1, e16, m1, tu, ma ; CHECK-NEXT: vslideup.vx v10, v12, a0 ; CHECK-NEXT: vsetvli zero, a0, e16, m1, tu, ma -; CHECK-NEXT: vslideup.vi v11, v12, 0 +; CHECK-NEXT: vslidedown.vi v11, v12, 0 ; CHECK-NEXT: vsetvli zero, a1, e16, m1, tu, ma ; CHECK-NEXT: vslideup.vx v11, v12, a0 ; CHECK-NEXT: vsetvli a0, zero, e16, m4, ta, ma @@ -1120,7 +1120,7 @@ ; CHECK-NEXT: vsetvli zero, a1, e16, m1, tu, ma ; CHECK-NEXT: vslideup.vx v10, v12, a0 ; CHECK-NEXT: vsetvli zero, a0, e16, m1, tu, ma -; CHECK-NEXT: vslideup.vi v11, v12, 0 +; CHECK-NEXT: vslidedown.vi v11, v12, 0 ; CHECK-NEXT: vsetvli zero, a1, e16, m1, tu, ma ; CHECK-NEXT: vslideup.vx v11, v12, a0 ; CHECK-NEXT: vsetvli a0, zero, e16, m4, ta, ma