Skip to content

Commit 208edf7

Browse files
committed
[RISCV] Fix assertion in lowerEXTRACT_SUBVECTOR
This fixes a crash when lowering an extract_subvector like: t0:v1i64 = extract_subvector t1:v2i64, 1 Whilst we never need a vslidedown with M1 on scalable vector types, we might need to do it for v1i64/v1f64, since the smallest container type for it is nxv1i64/nxv1f64. The lowering code is still correct for this case, but the assertion was too strict. The actual invariant we're relying on is that ContainerSubVecVT's LMUL <= M1, not < M1. Hence why we handled v2i32 fine, because its container type was nxv1i32 and MF2.
1 parent 990896a commit 208edf7

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9804,10 +9804,11 @@ SDValue RISCVTargetLowering::lowerEXTRACT_SUBVECTOR(SDValue Op,
98049804
return Op;
98059805
}
98069806

9807-
// Else SubVecVT is a fractional LMUL and may need to be slid down: if
9808-
// SubVecVT was > M1 then the index would need to be a multiple of VLMAX, and
9809-
// so would divide exactly.
9810-
assert(RISCVVType::decodeVLMUL(getLMUL(ContainerSubVecVT)).second);
9807+
// Else SubVecVT is M1 or smaller and may need to be slid down: if SubVecVT
9808+
// was > M1 then the index would need to be a multiple of VLMAX, and so would
9809+
// divide exactly.
9810+
assert(RISCVVType::decodeVLMUL(getLMUL(ContainerSubVecVT)).second ||
9811+
getLMUL(ContainerSubVecVT) == RISCVII::VLMUL::LMUL_1);
98119812

98129813
// If the vector type is an LMUL-group type, extract a subvector equal to the
98139814
// nearest full vector register type.

llvm/test/CodeGen/RISCV/rvv/fixed-vectors-extract-subvector.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,16 @@ define void @extract_v8i1_nxv32i1_16(<vscale x 32 x i1> %x, ptr %y) {
857857
ret void
858858
}
859859

860+
define <1 x i64> @extract_v1i64_v2i64_1(<2 x i64> %x) {
861+
; CHECK-LABEL: extract_v1i64_v2i64_1:
862+
; CHECK: # %bb.0:
863+
; CHECK-NEXT: vsetivli zero, 1, e64, m1, ta, ma
864+
; CHECK-NEXT: vslidedown.vi v8, v8, 1
865+
; CHECK-NEXT: ret
866+
%v = call <1 x i64> @llvm.vector.extract.v1i64.v2i64(<2 x i64> %x, i64 1)
867+
ret <1 x i64> %v
868+
}
869+
860870
declare <2 x i1> @llvm.vector.extract.v2i1.v64i1(<64 x i1> %vec, i64 %idx)
861871
declare <8 x i1> @llvm.vector.extract.v8i1.v64i1(<64 x i1> %vec, i64 %idx)
862872

0 commit comments

Comments
 (0)