1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -mtriple=thumbv8.1m.main-none-eabi -mattr=+mve --verify-machineinstrs %s -o - | FileCheck %s
3
4define void @simple(i32* nocapture readonly %x, i32* nocapture readnone %y, i32* nocapture %z, i32 %m, i32 %n) {
5; CHECK-LABEL: simple:
6; CHECK:       @ %bb.0: @ %entry
7; CHECK-NEXT:    .save {r7, lr}
8; CHECK-NEXT:    push {r7, lr}
9; CHECK-NEXT:    ldr r1, [sp, #8]
10; CHECK-NEXT:    mov r12, r3
11; CHECK-NEXT:    movs r3, #0
12; CHECK-NEXT:    add.w lr, r1, #3
13; CHECK-NEXT:    cmp.w r3, lr, lsr #2
14; CHECK-NEXT:    beq .LBB0_3
15; CHECK-NEXT:  @ %bb.1: @ %do.body.preheader
16; CHECK-NEXT:    dlstp.32 lr, r1
17; CHECK-NEXT:  .LBB0_2: @ %do.body
18; CHECK-NEXT:    @ =>This Inner Loop Header: Depth=1
19; CHECK-NEXT:    vldrw.u32 q0, [r0], #16
20; CHECK-NEXT:    vaddva.s32 r12, q0
21; CHECK-NEXT:    letp lr, .LBB0_2
22; CHECK-NEXT:  .LBB0_3: @ %if.end
23; CHECK-NEXT:    str.w r12, [r2]
24; CHECK-NEXT:    pop {r7, pc}
25entry:
26  %add = add i32 %n, 3
27  %div = lshr i32 %add, 2
28  %cmp.not = icmp eq i32 %div, 0
29  br i1 %cmp.not, label %if.end, label %do.body
30
31do.body:                                          ; preds = %entry, %do.body
32  %n.addr.0 = phi i32 [ %sub, %do.body ], [ %n, %entry ]
33  %count.0 = phi i32 [ %sub3, %do.body ], [ %div, %entry ]
34  %s.0 = phi i32 [ %add2, %do.body ], [ %m, %entry ]
35  %x.addr.0 = phi i32* [ %add.ptr, %do.body ], [ %x, %entry ]
36  %0 = tail call <4 x i1> @llvm.arm.mve.vctp32(i32 %n.addr.0)
37  %1 = bitcast i32* %x.addr.0 to <4 x i32>*
38  %2 = load <4 x i32>, <4 x i32>* %1, align 4
39  %3 = tail call i32 @llvm.arm.mve.addv.predicated.v4i32.v4i1(<4 x i32> %2, i32 0, <4 x i1> %0)
40  %add2 = add nsw i32 %3, %s.0
41  %add.ptr = getelementptr inbounds i32, i32* %x.addr.0, i32 4
42  %sub = add i32 %n.addr.0, -4
43  %sub3 = add nsw i32 %count.0, -1
44  %cmp4 = icmp sgt i32 %count.0, 1
45  br i1 %cmp4, label %do.body, label %if.end
46
47if.end:                                           ; preds = %do.body, %entry
48  %s.1 = phi i32 [ %m, %entry ], [ %add2, %do.body ]
49  store i32 %s.1, i32* %z, align 4
50  ret void
51}
52
53define void @nested(i32* nocapture readonly %x, i32* nocapture readnone %y, i32* nocapture %z, i32 %m, i32 %n) {
54; CHECK-LABEL: nested:
55; CHECK:       @ %bb.0: @ %entry
56; CHECK-NEXT:    .save {r4, r5, r6, r7, r8, lr}
57; CHECK-NEXT:    push.w {r4, r5, r6, r7, r8, lr}
58; CHECK-NEXT:    cbz r3, .LBB1_8
59; CHECK-NEXT:  @ %bb.1: @ %for.body.preheader
60; CHECK-NEXT:    ldr r5, [sp, #24]
61; CHECK-NEXT:    mov.w r12, #0
62; CHECK-NEXT:    movs r1, #0
63; CHECK-NEXT:    b .LBB1_4
64; CHECK-NEXT:  .LBB1_2: @ in Loop: Header=BB1_4 Depth=1
65; CHECK-NEXT:    mov r4, r3
66; CHECK-NEXT:  .LBB1_3: @ %if.end
67; CHECK-NEXT:    @ in Loop: Header=BB1_4 Depth=1
68; CHECK-NEXT:    str.w r4, [r2, r1, lsl #2]
69; CHECK-NEXT:    adds r1, #1
70; CHECK-NEXT:    cmp r1, r3
71; CHECK-NEXT:    beq .LBB1_8
72; CHECK-NEXT:  .LBB1_4: @ %for.body
73; CHECK-NEXT:    @ =>This Loop Header: Depth=1
74; CHECK-NEXT:    @ Child Loop BB1_6 Depth 2
75; CHECK-NEXT:    adds r7, r5, #3
76; CHECK-NEXT:    cmp.w r12, r7, lsr #2
77; CHECK-NEXT:    beq .LBB1_2
78; CHECK-NEXT:  @ %bb.5: @ %do.body.preheader
79; CHECK-NEXT:    @ in Loop: Header=BB1_4 Depth=1
80; CHECK-NEXT:    bic r6, r7, #3
81; CHECK-NEXT:    dlstp.32 lr, r5
82; CHECK-NEXT:    mov r7, r5
83; CHECK-NEXT:    add.w r8, r0, r6, lsl #2
84; CHECK-NEXT:    mov r4, r3
85; CHECK-NEXT:  .LBB1_6: @ %do.body
86; CHECK-NEXT:    @ Parent Loop BB1_4 Depth=1
87; CHECK-NEXT:    @ => This Inner Loop Header: Depth=2
88; CHECK-NEXT:    vldrw.u32 q0, [r0], #16
89; CHECK-NEXT:    vaddva.s32 r4, q0
90; CHECK-NEXT:    letp lr, .LBB1_6
91; CHECK-NEXT:  @ %bb.7: @ %if.end.loopexit
92; CHECK-NEXT:    @ in Loop: Header=BB1_4 Depth=1
93; CHECK-NEXT:    subs r5, r5, r6
94; CHECK-NEXT:    mov r0, r8
95; CHECK-NEXT:    b .LBB1_3
96; CHECK-NEXT:  .LBB1_8: @ %for.cond.cleanup
97; CHECK-NEXT:    pop.w {r4, r5, r6, r7, r8, pc}
98entry:
99  %cmp20.not = icmp eq i32 %m, 0
100  br i1 %cmp20.not, label %for.cond.cleanup, label %for.body
101
102for.cond.cleanup:                                 ; preds = %if.end, %entry
103  ret void
104
105for.body:                                         ; preds = %entry, %if.end
106  %x.addr.023 = phi i32* [ %x.addr.2, %if.end ], [ %x, %entry ]
107  %a.022 = phi i32 [ %inc, %if.end ], [ 0, %entry ]
108  %n.addr.021 = phi i32 [ %n.addr.2, %if.end ], [ %n, %entry ]
109  %add = add i32 %n.addr.021, 3
110  %div = lshr i32 %add, 2
111  %cmp1.not = icmp eq i32 %div, 0
112  br i1 %cmp1.not, label %if.end, label %do.body.preheader
113
114do.body.preheader:                                ; preds = %for.body
115  %0 = and i32 %add, -4
116  %scevgep = getelementptr i32, i32* %x.addr.023, i32 %0
117  br label %do.body
118
119do.body:                                          ; preds = %do.body.preheader, %do.body
120  %n.addr.1 = phi i32 [ %sub, %do.body ], [ %n.addr.021, %do.body.preheader ]
121  %count.0 = phi i32 [ %sub4, %do.body ], [ %div, %do.body.preheader ]
122  %s.0 = phi i32 [ %add3, %do.body ], [ %m, %do.body.preheader ]
123  %x.addr.1 = phi i32* [ %add.ptr, %do.body ], [ %x.addr.023, %do.body.preheader ]
124  %1 = tail call <4 x i1> @llvm.arm.mve.vctp32(i32 %n.addr.1)
125  %2 = bitcast i32* %x.addr.1 to <4 x i32>*
126  %3 = load <4 x i32>, <4 x i32>* %2, align 4
127  %4 = tail call i32 @llvm.arm.mve.addv.predicated.v4i32.v4i1(<4 x i32> %3, i32 0, <4 x i1> %1)
128  %add3 = add nsw i32 %4, %s.0
129  %add.ptr = getelementptr inbounds i32, i32* %x.addr.1, i32 4
130  %sub = add i32 %n.addr.1, -4
131  %sub4 = add nsw i32 %count.0, -1
132  %cmp5 = icmp sgt i32 %count.0, 1
133  br i1 %cmp5, label %do.body, label %if.end.loopexit
134
135if.end.loopexit:                                  ; preds = %do.body
136  %5 = sub i32 %n.addr.021, %0
137  br label %if.end
138
139if.end:                                           ; preds = %if.end.loopexit, %for.body
140  %n.addr.2 = phi i32 [ %n.addr.021, %for.body ], [ %5, %if.end.loopexit ]
141  %s.1 = phi i32 [ %m, %for.body ], [ %add3, %if.end.loopexit ]
142  %x.addr.2 = phi i32* [ %x.addr.023, %for.body ], [ %scevgep, %if.end.loopexit ]
143  %arrayidx = getelementptr inbounds i32, i32* %z, i32 %a.022
144  store i32 %s.1, i32* %arrayidx, align 4
145  %inc = add nuw nsw i32 %a.022, 1
146  %exitcond.not = icmp eq i32 %inc, %m
147  br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
148}
149
150declare <4 x i1> @llvm.arm.mve.vctp32(i32)
151declare i32 @llvm.arm.mve.addv.predicated.v4i32.v4i1(<4 x i32>, i32, <4 x i1>)
152