1 ; RUN: opt -mtriple=armv8.1m.main -mattr=+mve -S -mve-tail-predication -disable-mve-tail-predication=false %s -o - | FileCheck %s
3 ; TODO: Support extending loads
4 ; CHECK-LABEL: mat_vec_sext_i16
5 ; CHECK-NOT: call {{.*}} @llvm.arm.vctp
6 define void @mat_vec_sext_i16(i16** nocapture readonly %A, i16* nocapture readonly %B, i32* noalias nocapture %C, i32 %N) {
8 %cmp24 = icmp eq i32 %N, 0
9 br i1 %cmp24, label %for.cond.cleanup, label %for.cond1.preheader.us.preheader
11 for.cond1.preheader.us.preheader: ; preds = %entry
12 %n.rnd.up = add i32 %N, 3
13 %n.vec = and i32 %n.rnd.up, -4
14 %trip.count.minus.1 = add i32 %N, -1
15 %broadcast.splatinsert28 = insertelement <4 x i32> undef, i32 %trip.count.minus.1, i32 0
16 %broadcast.splat29 = shufflevector <4 x i32> %broadcast.splatinsert28, <4 x i32> undef, <4 x i32> zeroinitializer
17 %tmp = add i32 %n.vec, -4
18 %tmp1 = lshr i32 %tmp, 2
19 %tmp2 = add nuw nsw i32 %tmp1, 1
20 br label %for.cond1.preheader.us
22 for.cond1.preheader.us: ; preds = %middle.block, %for.cond1.preheader.us.preheader
23 %i.025.us = phi i32 [ %inc10.us, %middle.block ], [ 0, %for.cond1.preheader.us.preheader ]
24 %arrayidx.us = getelementptr inbounds i16*, i16** %A, i32 %i.025.us
25 %tmp3 = load i16*, i16** %arrayidx.us, align 4
26 %arrayidx8.us = getelementptr inbounds i32, i32* %C, i32 %i.025.us
27 %arrayidx8.promoted.us = load i32, i32* %arrayidx8.us, align 4
28 %tmp4 = insertelement <4 x i32> <i32 undef, i32 0, i32 0, i32 0>, i32 %arrayidx8.promoted.us, i32 0
29 call void @llvm.set.loop.iterations.i32(i32 %tmp2)
32 vector.body: ; preds = %vector.body, %for.cond1.preheader.us
33 %index = phi i32 [ 0, %for.cond1.preheader.us ], [ %index.next, %vector.body ]
34 %vec.phi = phi <4 x i32> [ %tmp4, %for.cond1.preheader.us ], [ %tmp14, %vector.body ]
35 %tmp5 = phi i32 [ %tmp2, %for.cond1.preheader.us ], [ %tmp15, %vector.body ]
36 %broadcast.splatinsert = insertelement <4 x i32> undef, i32 %index, i32 0
37 %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> undef, <4 x i32> zeroinitializer
38 %induction = add <4 x i32> %broadcast.splat, <i32 0, i32 1, i32 2, i32 3>
39 %tmp6 = getelementptr inbounds i16, i16* %tmp3, i32 %index
40 %tmp7 = icmp ule <4 x i32> %induction, %broadcast.splat29
41 %tmp8 = bitcast i16* %tmp6 to <4 x i16>*
42 %wide.masked.load = call <4 x i16> @llvm.masked.load.v4i16.p0v4i16(<4 x i16>* %tmp8, i32 2, <4 x i1> %tmp7, <4 x i16> undef)
43 %tmp9 = sext <4 x i16> %wide.masked.load to <4 x i32>
44 %tmp10 = getelementptr inbounds i16, i16* %B, i32 %index
45 %tmp11 = bitcast i16* %tmp10 to <4 x i16>*
46 %wide.masked.load30 = call <4 x i16> @llvm.masked.load.v4i16.p0v4i16(<4 x i16>* %tmp11, i32 2, <4 x i1> %tmp7, <4 x i16> undef)
47 %tmp12 = sext <4 x i16> %wide.masked.load30 to <4 x i32>
48 %tmp13 = mul nsw <4 x i32> %tmp12, %tmp9
49 %tmp14 = add nsw <4 x i32> %tmp13, %vec.phi
50 %index.next = add i32 %index, 4
51 %tmp15 = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 %tmp5, i32 1)
52 %tmp16 = icmp ne i32 %tmp15, 0
53 br i1 %tmp16, label %vector.body, label %middle.block
55 middle.block: ; preds = %vector.body
56 %tmp17 = select <4 x i1> %tmp7, <4 x i32> %tmp14, <4 x i32> %vec.phi
57 %tmp18 = call i32 @llvm.experimental.vector.reduce.add.v4i32(<4 x i32> %tmp17)
58 store i32 %tmp18, i32* %arrayidx8.us, align 4
59 %inc10.us = add nuw i32 %i.025.us, 1
60 %exitcond27 = icmp eq i32 %inc10.us, %N
61 br i1 %exitcond27, label %for.cond.cleanup, label %for.cond1.preheader.us
63 for.cond.cleanup: ; preds = %middle.block, %entry
67 ; CHECK-LABEL: mat_vec_i32
71 ; CHECK: [[IV:%[^ ]+]] = phi i32 [ %N, %for.cond1.preheader.us ], [ [[REM:%[^ ]+]], %vector.body ]
72 ; CHECK: [[VCTP:%[^ ]+]] = call <4 x i1> @llvm.arm.vctp32(i32 [[IV]])
73 ; CHECK: [[REM]] = sub i32 [[IV]], 4
74 ; CHECK: call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* {{.*}}, i32 4, <4 x i1> [[VCTP]], <4 x i32> undef)
75 ; CHECK: call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* {{.*}}, i32 4, <4 x i1> [[VCTP]], <4 x i32> undef)
76 define void @mat_vec_i32(i32** nocapture readonly %A, i32* nocapture readonly %B, i32* noalias nocapture %C, i32 %N) {
78 %cmp23 = icmp eq i32 %N, 0
79 br i1 %cmp23, label %for.cond.cleanup, label %for.cond1.preheader.us.preheader
81 for.cond1.preheader.us.preheader: ; preds = %entry
82 %n.rnd.up = add i32 %N, 3
83 %n.vec = and i32 %n.rnd.up, -4
84 %trip.count.minus.1 = add i32 %N, -1
85 %broadcast.splatinsert27 = insertelement <4 x i32> undef, i32 %trip.count.minus.1, i32 0
86 %broadcast.splat28 = shufflevector <4 x i32> %broadcast.splatinsert27, <4 x i32> undef, <4 x i32> zeroinitializer
87 %tmp = add i32 %n.vec, -4
88 %tmp1 = lshr i32 %tmp, 2
89 %tmp2 = add nuw nsw i32 %tmp1, 1
90 br label %for.cond1.preheader.us
92 for.cond1.preheader.us: ; preds = %middle.block, %for.cond1.preheader.us.preheader
93 %i.024.us = phi i32 [ %inc9.us, %middle.block ], [ 0, %for.cond1.preheader.us.preheader ]
94 %arrayidx.us = getelementptr inbounds i32*, i32** %A, i32 %i.024.us
95 %tmp3 = load i32*, i32** %arrayidx.us, align 4
96 %arrayidx7.us = getelementptr inbounds i32, i32* %C, i32 %i.024.us
97 %arrayidx7.promoted.us = load i32, i32* %arrayidx7.us, align 4
98 %tmp4 = insertelement <4 x i32> <i32 undef, i32 0, i32 0, i32 0>, i32 %arrayidx7.promoted.us, i32 0
99 call void @llvm.set.loop.iterations.i32(i32 %tmp2)
100 br label %vector.body
102 vector.body: ; preds = %vector.body, %for.cond1.preheader.us
103 %index = phi i32 [ 0, %for.cond1.preheader.us ], [ %index.next, %vector.body ]
104 %vec.phi = phi <4 x i32> [ %tmp4, %for.cond1.preheader.us ], [ %tmp12, %vector.body ]
105 %tmp5 = phi i32 [ %tmp2, %for.cond1.preheader.us ], [ %tmp13, %vector.body ]
106 %broadcast.splatinsert = insertelement <4 x i32> undef, i32 %index, i32 0
107 %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> undef, <4 x i32> zeroinitializer
108 %induction = add <4 x i32> %broadcast.splat, <i32 0, i32 1, i32 2, i32 3>
109 %tmp6 = getelementptr inbounds i32, i32* %tmp3, i32 %index
110 %tmp7 = icmp ule <4 x i32> %induction, %broadcast.splat28
111 %tmp8 = bitcast i32* %tmp6 to <4 x i32>*
112 %wide.masked.load = call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* %tmp8, i32 4, <4 x i1> %tmp7, <4 x i32> undef)
113 %tmp9 = getelementptr inbounds i32, i32* %B, i32 %index
114 %tmp10 = bitcast i32* %tmp9 to <4 x i32>*
115 %wide.masked.load29 = call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* %tmp10, i32 4, <4 x i1> %tmp7, <4 x i32> undef)
116 %tmp11 = mul nsw <4 x i32> %wide.masked.load29, %wide.masked.load
117 %tmp12 = add nsw <4 x i32> %vec.phi, %tmp11
118 %index.next = add i32 %index, 4
119 %tmp13 = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 %tmp5, i32 1)
120 %tmp14 = icmp ne i32 %tmp13, 0
121 br i1 %tmp14, label %vector.body, label %middle.block
123 middle.block: ; preds = %vector.body
124 %tmp15 = select <4 x i1> %tmp7, <4 x i32> %tmp12, <4 x i32> %vec.phi
125 %tmp16 = call i32 @llvm.experimental.vector.reduce.add.v4i32(<4 x i32> %tmp15)
126 store i32 %tmp16, i32* %arrayidx7.us, align 4
127 %inc9.us = add nuw i32 %i.024.us, 1
128 %exitcond26 = icmp eq i32 %inc9.us, %N
129 br i1 %exitcond26, label %for.cond.cleanup, label %for.cond1.preheader.us
131 for.cond.cleanup: ; preds = %middle.block, %entry
135 ; Function Attrs: argmemonly nounwind readonly willreturn
136 declare <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>*, i32 immarg, <4 x i1>, <4 x i32>) #0
138 ; Function Attrs: argmemonly nounwind readonly willreturn
139 declare <4 x i16> @llvm.masked.load.v4i16.p0v4i16(<4 x i16>*, i32 immarg, <4 x i1>, <4 x i16>) #0
141 ; Function Attrs: nounwind readnone willreturn
142 declare i32 @llvm.experimental.vector.reduce.add.v4i32(<4 x i32>) #1
144 ; Function Attrs: noduplicate nounwind
145 declare void @llvm.set.loop.iterations.i32(i32) #2
147 ; Function Attrs: noduplicate nounwind
148 declare i32 @llvm.loop.decrement.reg.i32.i32.i32(i32, i32) #2
150 attributes #0 = { argmemonly nounwind readonly willreturn }
151 attributes #1 = { nounwind readnone willreturn }
152 attributes #2 = { noduplicate nounwind }