diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp index eccda73548e87..64110aafb1612 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp @@ -7066,7 +7066,7 @@ SDValue DAGTypeLegalizer::WidenVecOp_INSERT_SUBVECTOR(SDNode *N) { // We need to make sure that the indices are still valid, otherwise we might // widen what was previously well-defined to something undefined. - if (IndicesValid && InVec.isUndef() && N->getConstantOperandVal(2) == 0) + if (IndicesValid && N->getConstantOperandVal(2) == 0) return DAG.getNode(ISD::INSERT_SUBVECTOR, SDLoc(N), VT, InVec, SubVec, N->getOperand(2)); diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-insert-subvector.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-insert-subvector.ll index 5581754b0721a..8b4614a08b658 100644 --- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-insert-subvector.ll +++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-insert-subvector.ll @@ -1000,3 +1000,12 @@ define <4 x i32> @insert_extract_v8i32_v2i32_0(<2 x i32> %v) { %2 = call <4 x i32> @llvm.vector.extract.v4i32.v8i32(<8 x i32> %1, i64 0) ret <4 x i32> %2 } + +define @insert_nxv24i8_v48i8_0( %v, <48 x i8> %w) vscale_range(2) { +; CHECK-LABEL: insert_nxv24i8_v48i8_0: +; CHECK: # %bb.0: +; CHECK-NEXT: vmv4r.v v8, v12 +; CHECK-NEXT: ret + %x = call @llvm.vector.insert.v48i8.nxv24i8( %v, <48 x i8> %w, i64 0) + ret %x +}