2 ; RUN: opt -mtriple=thumbv8.1m.main -mve-tail-predication -disable-mve-tail-predication=false -mattr=+mve %s -S -o - | FileCheck %s
4 ; CHECK-LABEL: vec_mul_reduce_add
7 ; CHECK-NOT: phi i32 [ 0, %vector.ph ]
8 ; CHECK: [[ELTS:%[^ ]+]] = phi i32 [ %N, %vector.ph ], [ [[SUB:%[^ ]+]], %vector.body ]
9 ; CHECK: [[VCTP:%[^ ]+]] = call <4 x i1> @llvm.arm.vctp32(i32 [[ELTS]])
10 ; CHECK: [[SUB]] = sub i32 [[ELTS]], 4
11 ; CHECK: call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* {{.*}}, i32 4, <4 x i1> [[VCTP]]
12 ; CHECK: call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* {{.*}}, i32 4, <4 x i1> [[VCTP]],
14 ; CHECK: middle.block:
15 ; CHECK: [[VCTP_CLONE:%[^ ]+]] = call <4 x i1> @llvm.arm.vctp32(i32 [[ELTS]])
16 ; CHECK: [[VPSEL:%[^ ]+]] = select <4 x i1> [[VCTP_CLONE]],
17 ; CHECK: call i32 @llvm.experimental.vector.reduce.add.v4i32(<4 x i32> [[VPSEL]])
19 define i32 @vec_mul_reduce_add(i32* noalias nocapture readonly %a, i32* noalias nocapture readonly %b, i32 %N) {
21 %cmp8 = icmp eq i32 %N, 0
24 %2 = shl nuw i32 %1, 2
27 %5 = add nuw nsw i32 %4, 1
28 br i1 %cmp8, label %for.cond.cleanup, label %vector.ph
30 vector.ph: ; preds = %entry
31 %trip.count.minus.1 = add i32 %N, -1
32 %broadcast.splatinsert11 = insertelement <4 x i32> undef, i32 %trip.count.minus.1, i32 0
33 %broadcast.splat12 = shufflevector <4 x i32> %broadcast.splatinsert11, <4 x i32> undef, <4 x i32> zeroinitializer
34 call void @llvm.set.loop.iterations.i32(i32 %5)
37 vector.body: ; preds = %vector.body, %vector.ph
38 %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
39 %lsr.iv2 = phi i32* [ %scevgep3, %vector.body ], [ %a, %vector.ph ]
40 %lsr.iv = phi i32* [ %scevgep, %vector.body ], [ %b, %vector.ph ]
41 %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %9, %vector.body ]
42 %6 = phi i32 [ %5, %vector.ph ], [ %10, %vector.body ]
43 %lsr.iv24 = bitcast i32* %lsr.iv2 to <4 x i32>*
44 %lsr.iv1 = bitcast i32* %lsr.iv to <4 x i32>*
45 %broadcast.splatinsert = insertelement <4 x i32> undef, i32 %index, i32 0
46 %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> undef, <4 x i32> zeroinitializer
47 %induction = add <4 x i32> %broadcast.splat, <i32 0, i32 1, i32 2, i32 3>
48 %7 = icmp ule <4 x i32> %induction, %broadcast.splat12
49 %wide.masked.load = call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* %lsr.iv24, i32 4, <4 x i1> %7, <4 x i32> undef)
50 %wide.masked.load13 = call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* %lsr.iv1, i32 4, <4 x i1> %7, <4 x i32> undef)
51 %8 = mul nsw <4 x i32> %wide.masked.load13, %wide.masked.load
52 %9 = add nsw <4 x i32> %8, %vec.phi
53 %index.next = add i32 %index, 4
54 %scevgep = getelementptr i32, i32* %lsr.iv, i32 4
55 %scevgep3 = getelementptr i32, i32* %lsr.iv2, i32 4
56 %10 = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 %6, i32 1)
57 %11 = icmp ne i32 %10, 0
58 br i1 %11, label %vector.body, label %middle.block
60 middle.block: ; preds = %vector.body
61 %12 = icmp ule <4 x i32> %induction, %broadcast.splat12
62 %13 = select <4 x i1> %12, <4 x i32> %9, <4 x i32> %vec.phi
63 %14 = call i32 @llvm.experimental.vector.reduce.add.v4i32(<4 x i32> %13)
64 br label %for.cond.cleanup
66 for.cond.cleanup: ; preds = %middle.block, %entry
67 %res.0.lcssa = phi i32 [ 0, %entry ], [ %14, %middle.block ]
71 declare <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>*, i32 immarg, <4 x i1>, <4 x i32>)
72 declare i32 @llvm.experimental.vector.reduce.add.v4i32(<4 x i32>)
73 declare void @llvm.set.loop.iterations.i32(i32)
74 declare i32 @llvm.loop.decrement.reg.i32.i32.i32(i32, i32)