Compiler projects using llvm
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -loop-deletion -S < %s | FileCheck %s

@a = global i1 false, align 4

define i32 @main() {
; CHECK-LABEL: @main(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
; CHECK:       for.body:
; CHECK-NEXT:    [[D_015:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
; CHECK-NEXT:    call void @foo()
; CHECK-NEXT:    [[DOTB:%.*]] = load i1, i1* @a, align 4
; CHECK-NEXT:    [[CONV1:%.*]] = select i1 [[DOTB]], i32 -128, i32 1
; CHECK-NEXT:    [[CMP2_NOT:%.*]] = icmp ugt i32 [[CONV1]], [[D_015]]
; CHECK-NEXT:    br i1 [[CMP2_NOT]], label [[CLEANUP:%.*]], label [[FOR_INC8:%.*]]
; CHECK:       for.inc8:
; CHECK-NEXT:    [[INC9:%.*]] = add nuw nsw i32 [[D_015]], 1
; CHECK-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i32 [[INC9]], 19
; CHECK-NEXT:    br label [[CLEANUP]]
; CHECK:       cleanup:
; CHECK-NEXT:    store i1 true, i1* @a, align 4
; CHECK-NEXT:    ret i32 0
;
entry:
  br label %for.body

for.body:
  %d.015 = phi i32 [ 0, %entry ], [ %inc9, %for.inc8 ]
  call void @foo()
  %.b = load i1, i1* @a, align 4
  %conv1 = select i1 %.b, i32 -128, i32 1
  %cmp2.not = icmp ugt i32 %conv1, %d.015
  br i1 %cmp2.not, label %cleanup, label %for.inc8

for.inc8:
  %inc9 = add nuw nsw i32 %d.015, 1
  %exitcond.not = icmp eq i32 %inc9, 19
  br i1 %exitcond.not, label %cleanup, label %for.body

cleanup:
  store i1 true, i1* @a, align 4
  ret i32 0
}

declare void @foo()