[llvm] [RISCV] Combine (vp.splice (insert_elt poison, scalar, 0), vec, 0, mask, 1, vl) to vslide1up. (PR #144871)

Ming Yan via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 19 20:45:28 PDT 2025


================
@@ -305,11 +302,8 @@ define <vscale x 2 x i32> @test_vp_splice_nxv2i32_with_firstelt(i32 %first, <vsc
 define <vscale x 2 x float> @test_vp_splice_nxv2f32_with_firstelt(float %first, <vscale x 2 x float> %vb, <vscale x 2 x i1> %mask, i32 zeroext %evl) {
----------------
NexMing wrote:

This case doesn't occur in the official LLVM project, but it does occur in our downstream compiler.

Here's an example:
```
void test(int *restrict a, int *b) {
  for (int i = 0; i < 1024; ++i)
    a[i] = b[i] + b[i + 1];
}
```

```
define dso_local void @test(ptr noalias nocapture noundef writeonly %a, ptr nocapture noundef readonly %b) local_unnamed_addr #0 {
entry:
  %.pre = load i32, ptr %b, align 4, !tbaa !6
  %invariant.gep = getelementptr i8, ptr %b, i64 4
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %entry
  %scalar.ind = phi i64 [ 0, %entry ], [ %next.ind, %vector.body ]
  %recur.phi = phi i32 [ %.pre, %entry ], [ %5, %vector.body ]
  %trip.count = phi i64 [ 1024, %entry ], [ %remaining.trip.count, %vector.body ]
  %evl = tail call i32 @llvm.experimental.get.vector.length.i64(i64 %trip.count, i32 16, i1 true)
  %0 = zext i32 %evl to i64
  %gep = getelementptr i32, ptr %invariant.gep, i64 %scalar.ind
  %1 = tail call <vscale x 16 x i32> @llvm.vp.load.nxv16i32.p0(ptr %gep, <vscale x 16 x i1> splat (i1 true), i32 %evl), !tbaa !6
  %2 = insertelement <vscale x 16 x i32> poison, i32 %recur.phi, i64 0
  %3 = tail call <vscale x 16 x i32> @llvm.experimental.vp.splice.nxv16i32(<vscale x 16 x i32> %2, <vscale x 16 x i32> %1, i32 0, <vscale x 16 x i1> splat (i1 true), i32 1, i32 %evl)
  %vp.binary = tail call <vscale x 16 x i32> @llvm.vp.add.nxv16i32(<vscale x 16 x i32> %1, <vscale x 16 x i32> %3, <vscale x 16 x i1> splat (i1 true), i32 %evl)
  %arrayidx514 = getelementptr inbounds i32, ptr %a, i64 %scalar.ind
  tail call void @llvm.vp.store.nxv16i32.p0(<vscale x 16 x i32> %vp.binary, ptr %arrayidx514, <vscale x 16 x i1> splat (i1 true), i32 %evl), !tbaa !6
  %remaining.trip.count = sub nuw i64 %trip.count, %0
  %4 = add i32 %evl, -1
  %5 = extractelement <vscale x 16 x i32> %1, i32 %4
  %next.ind = add i64 %scalar.ind, %0
  %6 = icmp eq i64 %remaining.trip.count, 0
  br i1 %6, label %for.cond.cleanup, label %vector.body, !llvm.loop !10

for.cond.cleanup:                                 ; preds = %vector.body
  ret void
}
```

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


More information about the llvm-commits mailing list