1 ; RUN: llc --force-dwarf-frame-section %s -o - | FileCheck %s
2 target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
3 target triple = "thumbv8.1m.main-arm-none-eabi"
11 ; for (int i = 0; i < n; ++i)
16 define hidden i32 @f(i32 %n) local_unnamed_addr #0 {
18 %vla = alloca i32, i32 %n, align 4
19 %call = call i32 @g(i32 %n, ptr nonnull %vla) #0
20 %cmp8 = icmp sgt i32 %n, 0
21 br i1 %cmp8, label %for.body.preheader, label %for.cond.cleanup
23 for.body.preheader: ; preds = %entry
25 %xtraiter = and i32 %n, 3
26 %1 = icmp ult i32 %0, 3
27 br i1 %1, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body.preheader.new
29 for.body.preheader.new: ; preds = %for.body.preheader
30 %unroll_iter = and i32 %n, -4
33 for.cond.cleanup.loopexit.unr-lcssa: ; preds = %for.body, %for.body.preheader
34 %add.lcssa.ph = phi i32 [ undef, %for.body.preheader ], [ %add.3, %for.body ]
35 %i.010.unr = phi i32 [ 0, %for.body.preheader ], [ %inc.3, %for.body ]
36 %s.09.unr = phi i32 [ 0, %for.body.preheader ], [ %add.3, %for.body ]
37 %lcmp.mod.not = icmp eq i32 %xtraiter, 0
38 br i1 %lcmp.mod.not, label %for.cond.cleanup, label %for.body.epil
40 for.body.epil: ; preds = %for.cond.cleanup.loopexit.unr-lcssa
41 %arrayidx.epil = getelementptr inbounds i32, ptr %vla, i32 %i.010.unr
42 %2 = load i32, ptr %arrayidx.epil, align 4
43 %add.epil = add nsw i32 %2, %s.09.unr
44 %epil.iter.cmp.not = icmp eq i32 %xtraiter, 1
45 br i1 %epil.iter.cmp.not, label %for.cond.cleanup, label %for.body.epil.1
47 for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit.unr-lcssa, %for.body.epil.2, %for.body.epil.1, %for.body.epil, %entry
48 %s.0.lcssa = phi i32 [ 0, %entry ], [ %add.lcssa.ph, %for.cond.cleanup.loopexit.unr-lcssa ], [ %add.epil, %for.body.epil ], [ %add.epil.1, %for.body.epil.1 ], [ %add.epil.2, %for.body.epil.2 ]
51 for.body: ; preds = %for.body, %for.body.preheader.new
52 %i.010 = phi i32 [ 0, %for.body.preheader.new ], [ %inc.3, %for.body ]
53 %s.09 = phi i32 [ 0, %for.body.preheader.new ], [ %add.3, %for.body ]
54 %niter = phi i32 [ %unroll_iter, %for.body.preheader.new ], [ %niter.nsub.3, %for.body ]
55 %arrayidx = getelementptr inbounds i32, ptr %vla, i32 %i.010
56 %3 = load i32, ptr %arrayidx, align 4
57 %add = add nsw i32 %3, %s.09
58 %inc = or i32 %i.010, 1
59 %arrayidx.1 = getelementptr inbounds i32, ptr %vla, i32 %inc
60 %4 = load i32, ptr %arrayidx.1, align 4
61 %add.1 = add nsw i32 %4, %add
62 %inc.1 = or i32 %i.010, 2
63 %arrayidx.2 = getelementptr inbounds i32, ptr %vla, i32 %inc.1
64 %5 = load i32, ptr %arrayidx.2, align 4
65 %add.2 = add nsw i32 %5, %add.1
66 %inc.2 = or i32 %i.010, 3
67 %arrayidx.3 = getelementptr inbounds i32, ptr %vla, i32 %inc.2
68 %6 = load i32, ptr %arrayidx.3, align 4
69 %add.3 = add nsw i32 %6, %add.2
70 %inc.3 = add nuw nsw i32 %i.010, 4
71 %niter.nsub.3 = add i32 %niter, -4
72 %niter.ncmp.3 = icmp eq i32 %niter.nsub.3, 0
73 br i1 %niter.ncmp.3, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body
75 for.body.epil.1: ; preds = %for.body.epil
76 %inc.epil = add nuw nsw i32 %i.010.unr, 1
77 %arrayidx.epil.1 = getelementptr inbounds i32, ptr %vla, i32 %inc.epil
78 %7 = load i32, ptr %arrayidx.epil.1, align 4
79 %add.epil.1 = add nsw i32 %7, %add.epil
80 %epil.iter.cmp.1.not = icmp eq i32 %xtraiter, 2
81 br i1 %epil.iter.cmp.1.not, label %for.cond.cleanup, label %for.body.epil.2
83 for.body.epil.2: ; preds = %for.body.epil.1
84 %inc.epil.1 = add nuw nsw i32 %i.010.unr, 2
85 %arrayidx.epil.2 = getelementptr inbounds i32, ptr %vla, i32 %inc.epil.1
86 %8 = load i32, ptr %arrayidx.epil.2, align 4
87 %add.epil.2 = add nsw i32 %8, %add.epil.1
88 br label %for.cond.cleanup
92 ; CHECK: pac r12, lr, sp
93 ; CHECK-NEXT: .save {r4, r5, r6, r7, lr}
94 ; CHECK-NEXT: push {r4, r5, r6, r7, lr}
95 ; CHECK-NEXT: .cfi_def_cfa_offset 20
96 ; CHECK-NEXT: .cfi_offset lr, -4
97 ; CHECK-NEXT: .cfi_offset r7, -8
98 ; CHECK-NEXT: .cfi_offset r6, -12
99 ; CHECK-NEXT: .cfi_offset r5, -16
100 ; CHECK-NEXT: .cfi_offset r4, -20
101 ; CHECK-NEXT: .setfp r7, sp, #12
102 ; CHECK-NEXT: add r7, sp, #12
103 ; CHECK-NEXT: .cfi_def_cfa r7, 8
104 ; CHECK-NEXT: .save {r8, r9, ra_auth_code}
105 ; CHECK-NEXT: push.w {r8, r9, r12}
106 ; CHECK-NEXT: .cfi_offset ra_auth_code, -24
107 ; CHECK-NEXT: .cfi_offset r9, -28
108 ; CHECK-NEXT: .cfi_offset r8, -32
110 ; CHECK: sub.w r[[N:[0-9]*]], r7, #24
111 ; CHECK-NEXT: mov sp, r[[N]]
112 ; CHECK-NEXT: pop.w {r8, r9, r12}
113 ; CHECK-NEXT: pop.w {r4, r5, r6, r7, lr}
114 ; CHECK-NEXT: aut r12, lr, sp
117 declare dso_local i32 @g(i32, ptr) local_unnamed_addr #0
119 attributes #0 = { nounwind }
121 !llvm.module.flags = !{!0, !1, !2}
123 !0 = !{i32 8, !"branch-target-enforcement", i32 0}
124 !1 = !{i32 8, !"sign-return-address", i32 1}
125 !2 = !{i32 8, !"sign-return-address-all", i32 0}