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.p0(ptr {{.*}}, i32 4, <4 x i1> [[VCTP]]
15 ; CHECK: call <4 x i32> @llvm.masked.load.v4i32.p0(ptr {{.*}}, 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(ptr noalias nocapture readonly %a, ptr 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 ptr [ %scevgep3, %vector.body ], [ %a, %vector.ph ]
39 %lsr.iv = phi ptr [ %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 %7 = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 %index, i32 %N)
43 %wide.masked.load = call <4 x i32> @llvm.masked.load.v4i32.p0(ptr %lsr.iv2, i32 4, <4 x i1> %7, <4 x i32> undef)
44 %wide.masked.load13 = call <4 x i32> @llvm.masked.load.v4i32.p0(ptr %lsr.iv, i32 4, <4 x i1> %7, <4 x i32> undef)
45 %8 = mul nsw <4 x i32> %wide.masked.load13, %wide.masked.load
46 %9 = add nsw <4 x i32> %8, %vec.phi
47 %index.next = add i32 %index, 4
48 %scevgep = getelementptr i32, ptr %lsr.iv, i32 4
49 %scevgep3 = getelementptr i32, ptr %lsr.iv2, i32 4
50 %10 = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 %6, i32 1)
51 %11 = icmp ne i32 %10, 0
52 br i1 %11, label %vector.body, label %middle.block
54 middle.block: ; preds = %vector.body
55 %12 = select <4 x i1> %7, <4 x i32> %9, <4 x i32> %vec.phi
56 %13 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %12)
57 br label %for.cond.cleanup
59 for.cond.cleanup: ; preds = %middle.block, %entry
60 %res.0.lcssa = phi i32 [ 0, %entry ], [ %13, %middle.block ]
64 declare <4 x i32> @llvm.masked.load.v4i32.p0(ptr, i32 immarg, <4 x i1>, <4 x i32>)
65 declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>)
66 declare i32 @llvm.start.loop.iterations.i32(i32)
67 declare i32 @llvm.loop.decrement.reg.i32.i32.i32(i32, i32)
68 declare <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32, i32)