[llvm] [RISCV] Fix crash when lowering fixed length insert_subvector into undef at 0 (PR #67535)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 27 10:07:38 PDT 2023


================
@@ -636,3 +636,21 @@ declare <vscale x 2 x i16> @llvm.vector.insert.v2i16.nxv2i16(<vscale x 2 x i16>,
 declare <vscale x 8 x i32> @llvm.vector.insert.v2i32.nxv8i32(<vscale x 8 x i32>, <2 x i32>, i64)
 declare <vscale x 8 x i32> @llvm.vector.insert.v4i32.nxv8i32(<vscale x 8 x i32>, <4 x i32>, i64)
 declare <vscale x 8 x i32> @llvm.vector.insert.v8i32.nxv8i32(<vscale x 8 x i32>, <8 x i32>, i64)
+
+; We emit insert_subvectors of fixed vectors at index 0 into undefs as a
+; copy_to_regclass or insert_subreg, depending on the register classes of the
+; vector types. Make sure that we use the correct type and not the shrunken
+; LMUL=1 type, otherwise we will end up with an invalid extract_subvector when
+; converting it from scalable->fixed, e.g. we get this for VLEN=128:
+;
+;   t14: nxv2i32 = insert_subvector undef:nxv2i32, t4, Constant:i64<0>
+; t15: v8i32 = extract_subvector t14, Constant:i64<0>
+declare <4 x i32> @llvm.vector.extract.v4i32.v8i32(<8 x i32>, i64)
+define <4 x i32> @insert_extract_v8i32_v2i32_0(<2 x i32> %v) {
+; CHECK-LABEL: insert_extract_v8i32_v2i32_0:
----------------
lukel97 wrote:

The @llvm.vector.insert generates the bad extract_subvector, where it's extracting v8i32 from a nxv2i32, however on its own this doesn't get picked up or validated. 

IIUC it's only when we extract the bad extract_subvector with @llvm.vector.extract that this assertion here notices it:
https://github.com/llvm/llvm-project/blob/9eeb0293e27c0f1b44304fd9681dcd88fd9edc0a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp#L2047-L2057

The same assertion logic exists for selecting insert_subvector, but I think it gets combined away before the assertion can be triggered.

https://github.com/llvm/llvm-project/pull/67535


More information about the llvm-commits mailing list