1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=thumbv7 %s -o - | FileCheck %s
4 ; Test the branch to return in BB4 is converted to return.
6 define i32 @foo(ptr %x, i32 %n) {
8 ; CHECK: @ %bb.0: @ %entry
9 ; CHECK-NEXT: cmp r1, #1
10 ; CHECK-NEXT: blt .LBB0_4
11 ; CHECK-NEXT: @ %bb.1: @ %for.body.preheader
12 ; CHECK-NEXT: bic r3, r1, #3
13 ; CHECK-NEXT: mov r12, r0
14 ; CHECK-NEXT: cmp r1, #4
15 ; CHECK-NEXT: bhs .LBB0_3
16 ; CHECK-NEXT: @ %bb.2:
17 ; CHECK-NEXT: movs r0, #0
18 ; CHECK-NEXT: b .LBB0_6
19 ; CHECK-NEXT: .LBB0_3: @ %middle.block
20 ; CHECK-NEXT: cmp r1, r3
21 ; CHECK-NEXT: bne .LBB0_5
22 ; CHECK-NEXT: .LBB0_4:
23 ; CHECK-NEXT: movs r0, #0
25 ; CHECK-NEXT: .LBB0_5:
26 ; CHECK-NEXT: ldr.w r0, [r12]
27 ; CHECK-NEXT: .LBB0_6: @ %for.body.preheader1
28 ; CHECK-NEXT: subs r3, r1, r3
29 ; CHECK-NEXT: mvn r2, #12
30 ; CHECK-NEXT: and.w r1, r2, r1, lsl #2
31 ; CHECK-NEXT: add r1, r12
32 ; CHECK-NEXT: .LBB0_7: @ %for.body
33 ; CHECK-NEXT: @ =>This Inner Loop Header: Depth=1
34 ; CHECK-NEXT: ldr r2, [r1], #4
35 ; CHECK-NEXT: subs r3, #1
36 ; CHECK-NEXT: add r0, r2
37 ; CHECK-NEXT: bne .LBB0_7
38 ; CHECK-NEXT: @ %bb.8: @ %for.cond.cleanup
41 %n.vec = and i32 %n, -4
42 %cmp6 = icmp sgt i32 %n, 0
43 br i1 %cmp6, label %for.body.preheader, label %for.cond.cleanup
45 for.body.preheader: ; preds = %entry
46 %min.iters.check = icmp ult i32 %n, 4
47 br i1 %min.iters.check, label %for.body.preheader1, label %middle.block
50 %x3 = load i32, ptr %x, align 4
51 %cmp.n = icmp eq i32 %n.vec, %n
52 br i1 %cmp.n, label %for.cond.cleanup, label %for.body.preheader1
54 for.body.preheader1: ; preds = %middle.block, %for.body.preheader
55 %r.07.ph = phi i32 [ 0, %for.body.preheader ], [ %x3, %middle.block ]
58 for.body: ; preds = %for.body.preheader1, %for.body
59 %i.08 = phi i32 [ %inc, %for.body ], [ %n.vec, %for.body.preheader1 ]
60 %r.07 = phi i32 [ %add, %for.body ], [ %r.07.ph, %for.body.preheader1 ]
61 %arrayidx = getelementptr inbounds i32, ptr %x, i32 %i.08
62 %v5 = load i32, ptr %arrayidx, align 4
63 %add = add nsw i32 %v5, %r.07
64 %inc = add nuw nsw i32 %i.08, 1
65 %exitcond = icmp eq i32 %inc, %n
66 br i1 %exitcond, label %for.cond.cleanup, label %for.body
68 for.cond.cleanup: ; preds = %for.body, %middle.block, %entry
69 %r.0.lcssa = phi i32 [ 0, %entry ], [ 0, %middle.block ], [ %add, %for.body ]