1 ; RUN: opt -mtriple=thumbv8.1m.main -mve-tail-predication -disable-mve-tail-predication=false -mattr=+mve %s -S -o - | FileCheck %s
3 ; CHECK-LABEL: reduction_i32
4 ; CHECK: phi i32 [ 0, %entry ]
5 ; CHECK: phi <8 x i16> [ zeroinitializer, %entry ]
7 ; CHECK: [[PHI:%[^ ]+]] = phi i32 [ %N, %entry ], [ [[ELEMS:%[^ ]+]], %vector.body ]
8 ; CHECK: [[VCTP:%[^ ]+]] = call <8 x i1> @llvm.arm.vctp16(i32 [[PHI]])
9 ; CHECK: [[ELEMS]] = sub i32 [[PHI]], 8
10 ; CHECK: call <8 x i16> @llvm.masked.load.v8i16.p0v8i16(<8 x i16>* %tmp4, i32 4, <8 x i1> [[VCTP]], <8 x i16> undef)
11 ; CHECK: call <8 x i16> @llvm.masked.load.v8i16.p0v8i16(<8 x i16>* %tmp6, i32 4, <8 x i1> [[VCTP]], <8 x i16> undef)
12 define i16 @reduction_i32(i16* nocapture readonly %A, i16* nocapture readonly %B, i32 %N) {
15 %n.rnd.up = add nuw nsw i32 %tmp, 8
16 %n.vec = and i32 %n.rnd.up, -8
17 %broadcast.splatinsert1 = insertelement <8 x i32> undef, i32 %tmp, i32 0
18 %broadcast.splat2 = shufflevector <8 x i32> %broadcast.splatinsert1, <8 x i32> undef, <8 x i32> zeroinitializer
19 %0 = add i32 %n.vec, -8
21 %2 = add nuw nsw i32 %1, 1
22 call void @llvm.set.loop.iterations.i32(i32 %2)
25 vector.body: ; preds = %vector.body, %entry
26 %index = phi i32 [ 0, %entry ], [ %index.next, %vector.body ]
27 %vec.phi = phi <8 x i16> [ zeroinitializer, %entry ], [ %tmp8, %vector.body ]
28 %3 = phi i32 [ %2, %entry ], [ %4, %vector.body ]
29 %broadcast.splatinsert = insertelement <8 x i32> undef, i32 %index, i32 0
30 %broadcast.splat = shufflevector <8 x i32> %broadcast.splatinsert, <8 x i32> undef, <8 x i32> zeroinitializer
31 %induction = add <8 x i32> %broadcast.splat, <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
32 %tmp2 = getelementptr inbounds i16, i16* %A, i32 %index
33 %tmp3 = icmp ule <8 x i32> %induction, %broadcast.splat2
34 %tmp4 = bitcast i16* %tmp2 to <8 x i16>*
35 %wide.masked.load = call <8 x i16> @llvm.masked.load.v8i16.p0v8i16(<8 x i16>* %tmp4, i32 4, <8 x i1> %tmp3, <8 x i16> undef)
36 %tmp5 = getelementptr inbounds i16, i16* %B, i32 %index
37 %tmp6 = bitcast i16* %tmp5 to <8 x i16>*
38 %wide.masked.load3 = call <8 x i16> @llvm.masked.load.v8i16.p0v8i16(<8 x i16>* %tmp6, i32 4, <8 x i1> %tmp3, <8 x i16> undef)
39 %tmp7 = add <8 x i16> %wide.masked.load, %vec.phi
40 %tmp8 = add <8 x i16> %tmp7, %wide.masked.load3
41 %index.next = add nuw nsw i32 %index, 8
42 %4 = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 %3, i32 1)
43 %5 = icmp ne i32 %4, 0
44 br i1 %5, label %vector.body, label %middle.block
46 middle.block: ; preds = %vector.body
47 %vec.phi.lcssa = phi <8 x i16> [ %vec.phi, %vector.body ]
48 %.lcssa3 = phi <8 x i1> [ %tmp3, %vector.body ]
49 %.lcssa = phi <8 x i16> [ %tmp8, %vector.body ]
50 %tmp10 = select <8 x i1> %.lcssa3, <8 x i16> %.lcssa, <8 x i16> %vec.phi.lcssa
51 %rdx.shuf = shufflevector <8 x i16> %tmp10, <8 x i16> undef, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 undef, i32 undef, i32 undef, i32 undef>
52 %bin.rdx = add <8 x i16> %rdx.shuf, %tmp10
53 %rdx.shuf4 = shufflevector <8 x i16> %bin.rdx, <8 x i16> undef, <8 x i32> <i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
54 %bin.rdx5 = add <8 x i16> %rdx.shuf4, %bin.rdx
55 %rdx.shuf6 = shufflevector <8 x i16> %bin.rdx5, <8 x i16> undef, <8 x i32> <i32 1, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
56 %bin.rdx7 = add <8 x i16> %rdx.shuf6, %bin.rdx5
57 %tmp11 = extractelement <8 x i16> %bin.rdx7, i32 0
61 ; CHECK-LABEL: reduction_i32_with_scalar
62 ; CHECK: phi i32 [ 0, %entry ]
63 ; CHECK: phi <8 x i16> [ zeroinitializer, %entry ]
65 ; CHECK: [[PHI:%[^ ]+]] = phi i32 [ %N, %entry ], [ [[ELEMS:%[^ ]+]], %vector.body ]
66 ; CHECK: [[VCTP:%[^ ]+]] = call <8 x i1> @llvm.arm.vctp16(i32 [[PHI]])
67 ; CHECK: [[ELEMS]] = sub i32 [[PHI]], 8
68 ; CHECK: call <8 x i16> @llvm.masked.load.v8i16.p0v8i16(<8 x i16>* %tmp4, i32 4, <8 x i1> [[VCTP]], <8 x i16> undef)
69 define i16 @reduction_i32_with_scalar(i16* nocapture readonly %A, i16 %B, i32 %N) local_unnamed_addr {
72 %n.rnd.up = add nuw nsw i32 %tmp, 8
73 %n.vec = and i32 %n.rnd.up, -8
74 %broadcast.splatinsert1 = insertelement <8 x i32> undef, i32 %tmp, i32 0
75 %broadcast.splat2 = shufflevector <8 x i32> %broadcast.splatinsert1, <8 x i32> undef, <8 x i32> zeroinitializer
76 %broadcast.splatinsert3 = insertelement <8 x i16> undef, i16 %B, i32 0
77 %broadcast.splat4 = shufflevector <8 x i16> %broadcast.splatinsert3, <8 x i16> undef, <8 x i32> zeroinitializer
78 %0 = add i32 %n.vec, -8
80 %2 = add nuw nsw i32 %1, 1
81 call void @llvm.set.loop.iterations.i32(i32 %2)
84 vector.body: ; preds = %vector.body, %entry
85 %index = phi i32 [ 0, %entry ], [ %index.next, %vector.body ]
86 %vec.phi = phi <8 x i16> [ zeroinitializer, %entry ], [ %tmp6, %vector.body ]
87 %3 = phi i32 [ %2, %entry ], [ %4, %vector.body ]
88 %broadcast.splatinsert = insertelement <8 x i32> undef, i32 %index, i32 0
89 %broadcast.splat = shufflevector <8 x i32> %broadcast.splatinsert, <8 x i32> undef, <8 x i32> zeroinitializer
90 %induction = add <8 x i32> %broadcast.splat, <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
91 %tmp2 = getelementptr inbounds i16, i16* %A, i32 %index
92 %tmp3 = icmp ule <8 x i32> %induction, %broadcast.splat2
93 %tmp4 = bitcast i16* %tmp2 to <8 x i16>*
94 %wide.masked.load = call <8 x i16> @llvm.masked.load.v8i16.p0v8i16(<8 x i16>* %tmp4, i32 4, <8 x i1> %tmp3, <8 x i16> undef)
95 %tmp5 = add <8 x i16> %vec.phi, %broadcast.splat4
96 %tmp6 = add <8 x i16> %tmp5, %wide.masked.load
97 %index.next = add nuw nsw i32 %index, 8
98 %4 = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 %3, i32 1)
99 %5 = icmp ne i32 %4, 0
100 br i1 %5, label %vector.body, label %middle.block
102 middle.block: ; preds = %vector.body
103 %tmp8 = select <8 x i1> %tmp3, <8 x i16> %tmp6, <8 x i16> %vec.phi
104 %rdx.shuf = shufflevector <8 x i16> %tmp8, <8 x i16> undef, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 undef, i32 undef, i32 undef, i32 undef>
105 %bin.rdx = add <8 x i16> %rdx.shuf, %tmp8
106 %rdx.shuf5 = shufflevector <8 x i16> %bin.rdx, <8 x i16> undef, <8 x i32> <i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
107 %bin.rdx6 = add <8 x i16> %rdx.shuf5, %bin.rdx
108 %rdx.shuf7 = shufflevector <8 x i16> %bin.rdx6, <8 x i16> undef, <8 x i32> <i32 1, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
109 %bin.rdx8 = add <8 x i16> %rdx.shuf7, %bin.rdx6
110 %tmp9 = extractelement <8 x i16> %bin.rdx8, i32 0
114 declare <8 x i16> @llvm.masked.load.v8i16.p0v8i16(<8 x i16>*, i32 immarg, <8 x i1>, <8 x i16>)
115 declare void @llvm.set.loop.iterations.i32(i32)
116 declare i32 @llvm.loop.decrement.reg.i32.i32.i32(i32, i32)