diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp index 752fed3d479a..5b5dca4b541d 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -3566,7 +3566,8 @@ static SDValue matchSplatAsGather(SDValue SplatVal, MVT VT, const SDLoc &DL, // FIXME: Support i1 vectors, maybe by promoting to i8? MVT EltTy = VT.getVectorElementType(); MVT SrcVT = Src.getSimpleValueType(); - if (EltTy == MVT::i1 || EltTy != SrcVT.getVectorElementType()) + if (EltTy == MVT::i1 || EltTy != SrcVT.getVectorElementType() || + !DAG.getTargetLoweringInfo().isTypeLegal(SrcVT)) return SDValue(); SDValue Idx = SplatVal.getOperand(1); // The index must be a legal type. diff --git a/llvm/test/CodeGen/RISCV/rvv/splat-vectors.ll b/llvm/test/CodeGen/RISCV/rvv/splat-vectors.ll index 47db3da3fbe7..e1d3bbea18b7 100644 --- a/llvm/test/CodeGen/RISCV/rvv/splat-vectors.ll +++ b/llvm/test/CodeGen/RISCV/rvv/splat-vectors.ll @@ -230,6 +230,21 @@ define <8 x float> @splat_idx_nxv4f32_v8f32_constant_7( %v) ret <8 x float> %splat } +; This test shouldn't crash. +define @splat_idx_illegal_type(<3 x float> %v) { +; CHECK-LABEL: splat_idx_illegal_type: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, ma +; CHECK-NEXT: vrgather.vi v9, v8, 0 +; CHECK-NEXT: vmv.v.v v8, v9 +; CHECK-NEXT: ret +entry: + %x = extractelement <3 x float> %v, i64 0 + %ins = insertelement poison, float %x, i64 0 + %splat = shufflevector %ins, poison, zeroinitializer + ret %splat +} + ; Negative test, vscale might be 4 define <8 x float> @splat_idx_nxv4f32_v8f32_constant_8( %v) { ; CHECK-LABEL: splat_idx_nxv4f32_v8f32_constant_8: