llvm/llvm/test/CodeGen/Thumb/branch-to-return.ll

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=thumbv7 %s -o - | FileCheck %s

; Test the branch to return in BB4 is converted to return.

define i32 @foo(ptr %x, i32 %n) {
; CHECK-LABEL: foo:
; CHECK:       @ %bb.0: @ %entry
; CHECK-NEXT:    cmp r1, #1
; CHECK-NEXT:    blt .LBB0_4
; CHECK-NEXT:  @ %bb.1: @ %for.body.preheader
; CHECK-NEXT:    bic r3, r1, #3
; CHECK-NEXT:    mov r12, r0
; CHECK-NEXT:    cmp r1, #4
; CHECK-NEXT:    bhs .LBB0_3
; CHECK-NEXT:  @ %bb.2:
; CHECK-NEXT:    movs r0, #0
; CHECK-NEXT:    b .LBB0_6
; CHECK-NEXT:  .LBB0_3: @ %middle.block
; CHECK-NEXT:    cmp r1, r3
; CHECK-NEXT:    bne .LBB0_5
; CHECK-NEXT:  .LBB0_4:
; CHECK-NEXT:    movs r0, #0
; CHECK-NEXT:    bx lr
; CHECK-NEXT:  .LBB0_5:
; CHECK-NEXT:    ldr.w r0, [r12]
; CHECK-NEXT:  .LBB0_6: @ %for.body.preheader1
; CHECK-NEXT:    subs r3, r1, r3
; CHECK-NEXT:    mvn r2, #12
; CHECK-NEXT:    and.w r1, r2, r1, lsl #2
; CHECK-NEXT:    add r1, r12
; CHECK-NEXT:  .LBB0_7: @ %for.body
; CHECK-NEXT:    @ =>This Inner Loop Header: Depth=1
; CHECK-NEXT:    ldr r2, [r1], #4
; CHECK-NEXT:    subs r3, #1
; CHECK-NEXT:    add r0, r2
; CHECK-NEXT:    bne .LBB0_7
; CHECK-NEXT:  @ %bb.8: @ %for.cond.cleanup
; CHECK-NEXT:    bx lr
entry:
  %n.vec = and i32 %n, -4
  %cmp6 = icmp sgt i32 %n, 0
  br i1 %cmp6, label %for.body.preheader, label %for.cond.cleanup

for.body.preheader:                               ; preds = %entry
  %min.iters.check = icmp ult i32 %n, 4
  br i1 %min.iters.check, label %for.body.preheader1, label %middle.block

middle.block:
  %x3 = load i32, ptr %x, align 4
  %cmp.n = icmp eq i32 %n.vec, %n
  br i1 %cmp.n, label %for.cond.cleanup, label %for.body.preheader1

for.body.preheader1:                              ; preds = %middle.block, %for.body.preheader
  %r.07.ph = phi i32 [ 0, %for.body.preheader ], [ %x3, %middle.block ]
  br label %for.body

for.body:                                         ; preds = %for.body.preheader1, %for.body
  %i.08 = phi i32 [ %inc, %for.body ], [ %n.vec, %for.body.preheader1 ]
  %r.07 = phi i32 [ %add, %for.body ], [ %r.07.ph, %for.body.preheader1 ]
  %arrayidx = getelementptr inbounds i32, ptr %x, i32 %i.08
  %v5 = load i32, ptr %arrayidx, align 4
  %add = add nsw i32 %v5, %r.07
  %inc = add nuw nsw i32 %i.08, 1
  %exitcond = icmp eq i32 %inc, %n
  br i1 %exitcond, label %for.cond.cleanup, label %for.body

for.cond.cleanup:                                 ; preds = %for.body, %middle.block, %entry
  %r.0.lcssa = phi i32 [ 0, %entry ], [ 0, %middle.block ], [ %add, %for.body ]
  ret i32 %r.0.lcssa
}