[PATCH] D153519: [RISCV] Widen insert_subvector ops for fixed insert into scalable

Luke Lau via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 22 03:46:14 PDT 2023


luke created this revision.
luke added reviewers: craig.topper, reames, frasercrmck.
Herald added subscribers: jobnoorman, asb, pmatos, VincentWu, vkmr, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
luke requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, alextsao1999, eopXD, MaskRay.
Herald added a project: LLVM.

Currently when widening operands for insert_subvector nodes, we check
first that the indices are valid by seeing if the subvector is
statically known to be smaller than or equal to the in-place vector.

However, it's also valid to insert a fixed subvector into a scalable
vector where we can't statically determine it, e.g. v8i32 into nxv4i32:

> Elements IDX through (IDX + num_elements(T) - 1) must be valid VECTOR1
> indices. If this condition cannot be determined statically but is
> false at runtime, then the result vector is undefined.

This patch relaxes the check to allow for this case, and fixes a crash
when lowering a @llvm.vector.insert intrinsic. Fixes #63437


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153519

Files:
  llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
  llvm/test/CodeGen/RISCV/rvv/insert-subvector.ll


Index: llvm/test/CodeGen/RISCV/rvv/insert-subvector.ll
===================================================================
--- llvm/test/CodeGen/RISCV/rvv/insert-subvector.ll
+++ llvm/test/CodeGen/RISCV/rvv/insert-subvector.ll
@@ -495,6 +495,14 @@
   ret void
 }
 
+define <vscale x 4 x i64> @insert_nxv4i64_nxv3i64(<3 x i64> %sv) {
+; CHECK-LABEL: insert_nxv4i64_nxv3i64:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    ret
+  %vec = call <vscale x 4 x i64> @llvm.vector.insert.nxv4i64.v3i64(<vscale x 4 x i64> undef, <3 x i64> %sv, i64 0)
+  ret <vscale x 4 x i64> %vec
+}
+
 declare <vscale x 4 x i1> @llvm.vector.insert.nxv1i1.nxv4i1(<vscale x 4 x i1>, <vscale x 1 x i1>, i64)
 declare <vscale x 32 x i1> @llvm.vector.insert.nxv8i1.nxv32i1(<vscale x 32 x i1>, <vscale x 8 x i1>, i64)
 
@@ -512,3 +520,5 @@
 declare <vscale x 16 x i32> @llvm.vector.insert.nxv2i32.nxv16i32(<vscale x 16 x i32>, <vscale x 2 x i32>, i64 %idx)
 declare <vscale x 16 x i32> @llvm.vector.insert.nxv4i32.nxv16i32(<vscale x 16 x i32>, <vscale x 4 x i32>, i64 %idx)
 declare <vscale x 16 x i32> @llvm.vector.insert.nxv8i32.nxv16i32(<vscale x 16 x i32>, <vscale x 8 x i32>, i64 %idx)
+
+declare <vscale x 4 x i64> @llvm.vector.insert.nxv4i64.v3i64(<vscale x 4 x i64>, <3 x i64>, i64 %idx)
Index: llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
@@ -6241,13 +6241,15 @@
 SDValue DAGTypeLegalizer::WidenVecOp_INSERT_SUBVECTOR(SDNode *N) {
   EVT VT = N->getValueType(0);
   SDValue SubVec = N->getOperand(1);
+  EVT SubVT = SubVec.getValueType();
   SDValue InVec = N->getOperand(0);
 
   if (getTypeAction(SubVec.getValueType()) == TargetLowering::TypeWidenVector)
     SubVec = GetWidenedVector(SubVec);
 
-  if (SubVec.getValueType().knownBitsLE(VT) && InVec.isUndef() &&
-      N->getConstantOperandVal(2) == 0)
+  bool IndicesValid = SubVT.knownBitsLE(VT) ||
+                      (VT.isScalableVector() && SubVT.isFixedLengthVector());
+  if (IndicesValid && InVec.isUndef() && N->getConstantOperandVal(2) == 0)
     return DAG.getNode(ISD::INSERT_SUBVECTOR, SDLoc(N), VT, InVec, SubVec,
                        N->getOperand(2));
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153519.533533.patch
Type: text/x-patch
Size: 2299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230622/b812a27d/attachment.bin>


More information about the llvm-commits mailing list