1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -mtriple=thumbv8.1m.main -mattr=+mve.fp -mve-tail-predication -tail-predication=enabled %s -S -o - | FileCheck %s
3
4define hidden i32 @_Z4loopPiPjiS0_i(i32* noalias nocapture readonly %s1, i32* noalias nocapture readonly %s2, i32 %x, i32* noalias nocapture %d, i32 %n) {
5; CHECK-LABEL: @_Z4loopPiPjiS0_i(
6; CHECK-NEXT:  entry:
7; CHECK-NEXT:    [[CMP63:%.*]] = icmp sgt i32 [[N:%.*]], 0
8; CHECK-NEXT:    br i1 [[CMP63]], label [[FOR_BODY_LR_PH:%.*]], label [[FOR_COND_CLEANUP:%.*]]
9; CHECK:       for.body.lr.ph:
10; CHECK-NEXT:    [[TOBOOL:%.*]] = icmp eq i32 [[X:%.*]], 0
11; CHECK-NEXT:    [[N_RND_UP77:%.*]] = add nuw i32 [[N]], 3
12; CHECK-NEXT:    [[N_VEC79:%.*]] = and i32 [[N_RND_UP77]], -4
13; CHECK-NEXT:    [[TRIP_COUNT_MINUS_183:%.*]] = add nsw i32 [[N]], -1
14; CHECK-NEXT:    [[TMP0:%.*]] = add i32 [[N_VEC79]], -4
15; CHECK-NEXT:    [[TMP1:%.*]] = lshr i32 [[TMP0]], 2
16; CHECK-NEXT:    [[TMP2:%.*]] = add nuw nsw i32 [[TMP1]], 1
17; CHECK-NEXT:    [[TMP3:%.*]] = add nuw nsw i32 [[TMP1]], 1
18; CHECK-NEXT:    br i1 [[TOBOOL]], label [[VECTOR_BODY75_PREHEADER:%.*]], label [[VECTOR_PH:%.*]]
19; CHECK:       vector.body75.preheader:
20; CHECK-NEXT:    [[START1:%.*]] = call i32 @llvm.start.loop.iterations.i32(i32 [[TMP2]])
21; CHECK-NEXT:    br label [[VECTOR_BODY75:%.*]]
22; CHECK:       vector.ph:
23; CHECK-NEXT:    [[BROADCAST_SPLATINSERT71:%.*]] = insertelement <4 x i32> undef, i32 [[X]], i32 0
24; CHECK-NEXT:    [[BROADCAST_SPLAT72:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT71]], <4 x i32> undef, <4 x i32> zeroinitializer
25; CHECK-NEXT:    [[START2:%.*]] = call i32 @llvm.start.loop.iterations.i32(i32 [[TMP3]])
26; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
27; CHECK:       vector.body:
28; CHECK-NEXT:    [[LSR_IV9:%.*]] = phi i32* [ [[SCEVGEP10:%.*]], [[VECTOR_BODY]] ], [ [[D:%.*]], [[VECTOR_PH]] ]
29; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
30; CHECK-NEXT:    [[TMP4:%.*]] = phi i32 [ [[START2]], [[VECTOR_PH]] ], [ [[TMP10:%.*]], [[VECTOR_BODY]] ]
31; CHECK-NEXT:    [[TMP5:%.*]] = phi i32 [ [[N]], [[VECTOR_PH]] ], [ [[TMP9:%.*]], [[VECTOR_BODY]] ]
32; CHECK-NEXT:    [[LSR_IV911:%.*]] = bitcast i32* [[LSR_IV9]] to <4 x i32>*
33; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> undef, i32 [[INDEX]], i32 0
34; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> undef, <4 x i32> zeroinitializer
35; CHECK-NEXT:    [[INDUCTION:%.*]] = add <4 x i32> [[BROADCAST_SPLAT]], <i32 0, i32 1, i32 2, i32 3>
36; CHECK-NEXT:    [[TMP6:%.*]] = insertelement <4 x i32> undef, i32 [[TRIP_COUNT_MINUS_183]], i32 0
37; CHECK-NEXT:    [[TMP7:%.*]] = shufflevector <4 x i32> [[TMP6]], <4 x i32> undef, <4 x i32> zeroinitializer
38; CHECK-NEXT:    [[TMP8:%.*]] = call <4 x i1> @llvm.arm.mve.vctp32(i32 [[TMP5]])
39; CHECK-NEXT:    [[TMP9]] = sub i32 [[TMP5]], 4
40; CHECK-NEXT:    call void @llvm.masked.store.v4i32.p0v4i32(<4 x i32> [[BROADCAST_SPLAT72]], <4 x i32>* [[LSR_IV911]], i32 4, <4 x i1> [[TMP8]])
41; CHECK-NEXT:    [[INDEX_NEXT]] = add i32 [[INDEX]], 4
42; CHECK-NEXT:    [[SCEVGEP10]] = getelementptr i32, i32* [[LSR_IV9]], i32 4
43; CHECK-NEXT:    [[TMP10]] = call i32 @llvm.loop.decrement.reg.i32(i32 [[TMP4]], i32 1)
44; CHECK-NEXT:    [[TMP11:%.*]] = icmp ne i32 [[TMP10]], 0
45; CHECK-NEXT:    br i1 [[TMP11]], label [[VECTOR_BODY]], label [[FOR_COND_CLEANUP]]
46; CHECK:       vector.body75:
47; CHECK-NEXT:    [[LSR_IV6:%.*]] = phi i32* [ [[S1:%.*]], [[VECTOR_BODY75_PREHEADER]] ], [ [[SCEVGEP7:%.*]], [[VECTOR_BODY75]] ]
48; CHECK-NEXT:    [[LSR_IV3:%.*]] = phi i32* [ [[S2:%.*]], [[VECTOR_BODY75_PREHEADER]] ], [ [[SCEVGEP4:%.*]], [[VECTOR_BODY75]] ]
49; CHECK-NEXT:    [[LSR_IV:%.*]] = phi i32* [ [[D]], [[VECTOR_BODY75_PREHEADER]] ], [ [[SCEVGEP:%.*]], [[VECTOR_BODY75]] ]
50; CHECK-NEXT:    [[INDEX80:%.*]] = phi i32 [ [[INDEX_NEXT81:%.*]], [[VECTOR_BODY75]] ], [ 0, [[VECTOR_BODY75_PREHEADER]] ]
51; CHECK-NEXT:    [[TMP12:%.*]] = phi i32 [ [[START1]], [[VECTOR_BODY75_PREHEADER]] ], [ [[TMP17:%.*]], [[VECTOR_BODY75]] ]
52; CHECK-NEXT:    [[LSR_IV68:%.*]] = bitcast i32* [[LSR_IV6]] to <4 x i32>*
53; CHECK-NEXT:    [[LSR_IV35:%.*]] = bitcast i32* [[LSR_IV3]] to <4 x i32>*
54; CHECK-NEXT:    [[LSR_IV2:%.*]] = bitcast i32* [[LSR_IV]] to <4 x i32>*
55; CHECK-NEXT:    [[BROADCAST_SPLATINSERT84:%.*]] = insertelement <4 x i32> undef, i32 [[INDEX80]], i32 0
56; CHECK-NEXT:    [[BROADCAST_SPLAT85:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT84]], <4 x i32> undef, <4 x i32> zeroinitializer
57; CHECK-NEXT:    [[INDUCTION86:%.*]] = add <4 x i32> [[BROADCAST_SPLAT85]], <i32 0, i32 1, i32 2, i32 3>
58; CHECK-NEXT:    [[TMP13:%.*]] = insertelement <4 x i32> undef, i32 [[TRIP_COUNT_MINUS_183]], i32 0
59; CHECK-NEXT:    [[TMP14:%.*]] = shufflevector <4 x i32> [[TMP13]], <4 x i32> undef, <4 x i32> zeroinitializer
60; CHECK-NEXT:    [[TMP15:%.*]] = icmp ule <4 x i32> [[INDUCTION86]], [[TMP14]]
61; CHECK-NEXT:    [[WIDE_MASKED_LOAD:%.*]] = call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* [[LSR_IV68]], i32 4, <4 x i1> [[TMP15]], <4 x i32> undef)
62; CHECK-NEXT:    [[WIDE_MASKED_LOAD89:%.*]] = call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* [[LSR_IV35]], i32 4, <4 x i1> [[TMP15]], <4 x i32> undef)
63; CHECK-NEXT:    [[TMP16:%.*]] = call <4 x i32> @llvm.usub.sat.v4i32(<4 x i32> [[WIDE_MASKED_LOAD89]], <4 x i32> [[WIDE_MASKED_LOAD]])
64; CHECK-NEXT:    call void @llvm.masked.store.v4i32.p0v4i32(<4 x i32> [[TMP16]], <4 x i32>* [[LSR_IV2]], i32 4, <4 x i1> [[TMP15]])
65; CHECK-NEXT:    [[INDEX_NEXT81]] = add i32 [[INDEX80]], 4
66; CHECK-NEXT:    [[SCEVGEP]] = getelementptr i32, i32* [[LSR_IV]], i32 4
67; CHECK-NEXT:    [[SCEVGEP4]] = getelementptr i32, i32* [[LSR_IV3]], i32 4
68; CHECK-NEXT:    [[SCEVGEP7]] = getelementptr i32, i32* [[LSR_IV6]], i32 4
69; CHECK-NEXT:    [[TMP17]] = call i32 @llvm.loop.decrement.reg.i32(i32 [[TMP12]], i32 1)
70; CHECK-NEXT:    [[TMP18:%.*]] = icmp ne i32 [[TMP17]], 0
71; CHECK-NEXT:    br i1 [[TMP18]], label [[VECTOR_BODY75]], label [[FOR_COND_CLEANUP]]
72; CHECK:       for.cond.cleanup:
73; CHECK-NEXT:    ret i32 0
74;
75entry:
76  %cmp63 = icmp sgt i32 %n, 0
77  br i1 %cmp63, label %for.body.lr.ph, label %for.cond.cleanup
78
79for.body.lr.ph:                                   ; preds = %entry
80  %tobool = icmp eq i32 %x, 0
81  %n.rnd.up77 = add nuw i32 %n, 3
82  %n.vec79 = and i32 %n.rnd.up77, -4
83  %trip.count.minus.183 = add nsw i32 %n, -1
84  %0 = add i32 %n.vec79, -4
85  %1 = lshr i32 %0, 2
86  %2 = add nuw nsw i32 %1, 1
87  %3 = add nuw nsw i32 %1, 1
88  br i1 %tobool, label %vector.body75.preheader, label %vector.ph
89
90vector.body75.preheader:                          ; preds = %for.body.lr.ph
91  %start1 = call i32 @llvm.start.loop.iterations.i32(i32 %2)
92  br label %vector.body75
93
94vector.ph:                                        ; preds = %for.body.lr.ph
95  %broadcast.splatinsert71 = insertelement <4 x i32> undef, i32 %x, i32 0
96  %broadcast.splat72 = shufflevector <4 x i32> %broadcast.splatinsert71, <4 x i32> undef, <4 x i32> zeroinitializer
97  %start2 = call i32 @llvm.start.loop.iterations.i32(i32 %3)
98  br label %vector.body
99
100vector.body:                                      ; preds = %vector.body, %vector.ph
101  %lsr.iv9 = phi i32* [ %scevgep10, %vector.body ], [ %d, %vector.ph ]
102  %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
103  %4 = phi i32 [ %start2, %vector.ph ], [ %8, %vector.body ]
104  %lsr.iv911 = bitcast i32* %lsr.iv9 to <4 x i32>*
105  %broadcast.splatinsert = insertelement <4 x i32> undef, i32 %index, i32 0
106  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> undef, <4 x i32> zeroinitializer
107  %induction = add <4 x i32> %broadcast.splat, <i32 0, i32 1, i32 2, i32 3>
108  %5 = insertelement <4 x i32> undef, i32 %trip.count.minus.183, i32 0
109  %6 = shufflevector <4 x i32> %5, <4 x i32> undef, <4 x i32> zeroinitializer
110  %7 = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 %index, i32 %n)
111  call void @llvm.masked.store.v4i32.p0v4i32(<4 x i32> %broadcast.splat72, <4 x i32>* %lsr.iv911, i32 4, <4 x i1> %7)
112  %index.next = add i32 %index, 4
113  %scevgep10 = getelementptr i32, i32* %lsr.iv9, i32 4
114  %8 = call i32 @llvm.loop.decrement.reg.i32(i32 %4, i32 1)
115  %9 = icmp ne i32 %8, 0
116  br i1 %9, label %vector.body, label %for.cond.cleanup
117
118vector.body75:                                    ; preds = %vector.body75, %vector.body75.preheader
119  %lsr.iv6 = phi i32* [ %s1, %vector.body75.preheader ], [ %scevgep7, %vector.body75 ]
120  %lsr.iv3 = phi i32* [ %s2, %vector.body75.preheader ], [ %scevgep4, %vector.body75 ]
121  %lsr.iv = phi i32* [ %d, %vector.body75.preheader ], [ %scevgep, %vector.body75 ]
122  %index80 = phi i32 [ %index.next81, %vector.body75 ], [ 0, %vector.body75.preheader ]
123  %10 = phi i32 [ %start1, %vector.body75.preheader ], [ %15, %vector.body75 ]
124  %lsr.iv68 = bitcast i32* %lsr.iv6 to <4 x i32>*
125  %lsr.iv35 = bitcast i32* %lsr.iv3 to <4 x i32>*
126  %lsr.iv2 = bitcast i32* %lsr.iv to <4 x i32>*
127  %broadcast.splatinsert84 = insertelement <4 x i32> undef, i32 %index80, i32 0
128  %broadcast.splat85 = shufflevector <4 x i32> %broadcast.splatinsert84, <4 x i32> undef, <4 x i32> zeroinitializer
129  %induction86 = add <4 x i32> %broadcast.splat85, <i32 0, i32 1, i32 2, i32 3>
130  %11 = insertelement <4 x i32> undef, i32 %trip.count.minus.183, i32 0
131  %12 = shufflevector <4 x i32> %11, <4 x i32> undef, <4 x i32> zeroinitializer
132  %13 = icmp ule <4 x i32> %induction86, %12
133  %wide.masked.load = call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* %lsr.iv68, i32 4, <4 x i1> %13, <4 x i32> undef)
134  %wide.masked.load89 = call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* %lsr.iv35, i32 4, <4 x i1> %13, <4 x i32> undef)
135  %14 = call <4 x i32> @llvm.usub.sat.v4i32(<4 x i32> %wide.masked.load89, <4 x i32> %wide.masked.load)
136  call void @llvm.masked.store.v4i32.p0v4i32(<4 x i32> %14, <4 x i32>* %lsr.iv2, i32 4, <4 x i1> %13)
137  %index.next81 = add i32 %index80, 4
138  %scevgep = getelementptr i32, i32* %lsr.iv, i32 4
139  %scevgep4 = getelementptr i32, i32* %lsr.iv3, i32 4
140  %scevgep7 = getelementptr i32, i32* %lsr.iv6, i32 4
141  %15 = call i32 @llvm.loop.decrement.reg.i32(i32 %10, i32 1)
142  %16 = icmp ne i32 %15, 0
143  br i1 %16, label %vector.body75, label %for.cond.cleanup
144
145for.cond.cleanup:                                 ; preds = %vector.body, %vector.body75, %entry
146  ret i32 0
147}
148declare void @llvm.masked.store.v4i32.p0v4i32(<4 x i32>, <4 x i32>*, i32 immarg, <4 x i1>)
149declare <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>*, i32 immarg, <4 x i1>, <4 x i32>)
150declare <4 x i32> @llvm.usub.sat.v4i32(<4 x i32>, <4 x i32>)
151declare i32 @llvm.start.loop.iterations.i32(i32)
152declare i32 @llvm.loop.decrement.reg.i32(i32, i32)
153
154declare <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32, i32)
155declare <8 x i1> @llvm.get.active.lane.mask.v8i1.i32(i32, i32)
156declare <16 x i1> @llvm.get.active.lane.mask.v16i1.i32(i32, i32)
157