1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=indvars < %s | FileCheck %s
6 define void @test(ptr %arr) {
9 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
11 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[IV_INC:%.*]], [[LOOP_LATCH:%.*]] ], [ 0, [[ENTRY:%.*]] ]
12 ; CHECK-NEXT: [[PREV:%.*]] = phi i32 [ [[V:%.*]], [[LOOP_LATCH]] ], [ 0, [[ENTRY]] ]
13 ; CHECK-NEXT: [[PTR:%.*]] = getelementptr inbounds i32, ptr [[ARR:%.*]], i64 [[IV]]
14 ; CHECK-NEXT: [[V]] = load i32, ptr [[PTR]], align 4
15 ; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i32 [[V]], 0
16 ; CHECK-NEXT: br i1 [[CMP1]], label [[IF:%.*]], label [[LOOP_LATCH]]
18 ; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[PREV]], 0
19 ; CHECK-NEXT: call void @use(i1 [[CMP2]])
20 ; CHECK-NEXT: br label [[LOOP_LATCH]]
22 ; CHECK-NEXT: [[IV_INC]] = add nuw nsw i64 [[IV]], 1
23 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[IV_INC]], 16
24 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP_HEADER]], label [[EXIT:%.*]]
26 ; CHECK-NEXT: ret void
32 %iv = phi i64 [ %iv.inc, %loop.latch ], [ 0, %entry ]
33 %prev = phi i32 [ %v, %loop.latch ], [ 0, %entry ]
34 %ptr = getelementptr inbounds i32, ptr %arr, i64 %iv
35 %v = load i32, ptr %ptr
36 %cmp1 = icmp sgt i32 %v, 0
37 br i1 %cmp1, label %if, label %loop.latch
40 %cmp2 = icmp slt i32 %prev, 0
41 call void @use(i1 %cmp2)
45 %iv.inc = add nuw nsw i64 %iv, 1
46 %cmp = icmp ult i64 %iv.inc, 16
47 br i1 %cmp, label %loop.header, label %exit