2 ; RUN: opt -mtriple=thumbv8.1m.main -mve-tail-predication -tail-predication=enabled -mattr=+mve %s -S -o - | FileCheck %s
4 ; CHECK-LABEL: vec_mul_reduce_add
7 ; CHECK: %start = call i32 @llvm.start.loop.iterations.i32
8 ; CHECK: br label %vector.body
11 ; CHECK: [[ELTS:%[^ ]+]] = phi i32 [ %N, %vector.ph ], [ [[SUB:%[^ ]+]], %vector.body ]
12 ; CHECK: [[VCTP:%[^ ]+]] = call <4 x i1> @llvm.arm.mve.vctp32(i32 [[ELTS]])
13 ; CHECK: [[SUB]] = sub i32 [[ELTS]], 4
14 ; CHECK: call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* {{.*}}, i32 4, <4 x i1> [[VCTP]]
15 ; CHECK: call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* {{.*}}, i32 4, <4 x i1> [[VCTP]],
17 ; CHECK: middle.block:
18 ; CHECK: [[VPSEL:%[^ ]+]] = select <4 x i1> [[VCTP]],
19 ; CHECK: call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[VPSEL]])
21 define i32 @vec_mul_reduce_add(i32* noalias nocapture readonly %a, i32* noalias nocapture readonly %b, i32 %N) {
23 %cmp8 = icmp eq i32 %N, 0
26 %2 = shl nuw i32 %1, 2
29 %5 = add nuw nsw i32 %4, 1
30 br i1 %cmp8, label %for.cond.cleanup, label %vector.ph
32 vector.ph: ; preds = %entry
33 %start = call i32 @llvm.start.loop.iterations.i32(i32 %5)
36 vector.body: ; preds = %vector.body, %vector.ph
37 %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
38 %lsr.iv2 = phi i32* [ %scevgep3, %vector.body ], [ %a, %vector.ph ]
39 %lsr.iv = phi i32* [ %scevgep, %vector.body ], [ %b, %vector.ph ]
40 %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %9, %vector.body ]
41 %6 = phi i32 [ %start, %vector.ph ], [ %10, %vector.body ]
42 %lsr.iv24 = bitcast i32* %lsr.iv2 to <4 x i32>*
43 %lsr.iv1 = bitcast i32* %lsr.iv to <4 x i32>*
44 %7 = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 %index, i32 %N)
45 %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)
46 %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)
47 %8 = mul nsw <4 x i32> %wide.masked.load13, %wide.masked.load
48 %9 = add nsw <4 x i32> %8, %vec.phi
49 %index.next = add i32 %index, 4
50 %scevgep = getelementptr i32, i32* %lsr.iv, i32 4
51 %scevgep3 = getelementptr i32, i32* %lsr.iv2, i32 4
52 %10 = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 %6, i32 1)
53 %11 = icmp ne i32 %10, 0
54 br i1 %11, label %vector.body, label %middle.block
56 middle.block: ; preds = %vector.body
57 %12 = select <4 x i1> %7, <4 x i32> %9, <4 x i32> %vec.phi
58 %13 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %12)
59 br label %for.cond.cleanup
61 for.cond.cleanup: ; preds = %middle.block, %entry
62 %res.0.lcssa = phi i32 [ 0, %entry ], [ %13, %middle.block ]
66 declare <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>*, i32 immarg, <4 x i1>, <4 x i32>)
67 declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>)
68 declare i32 @llvm.start.loop.iterations.i32(i32)
69 declare i32 @llvm.loop.decrement.reg.i32.i32.i32(i32, i32)
70 declare <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32, i32)