1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -indvars -S | FileCheck %s
3 ; RUN: opt < %s -passes=indvars -S | FileCheck %s
5 define void @test_signed(i32 %start) {
6 ; CHECK-LABEL: @test_signed(
8 ; CHECK-NEXT: [[COND:%.*]] = icmp ne i32 [[START:%.*]], -2147483648
9 ; CHECK-NEXT: br i1 [[COND]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
10 ; CHECK: loop.preheader:
11 ; CHECK-NEXT: br label [[LOOP:%.*]]
13 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[GUARDED:%.*]] ], [ [[START]], [[LOOP_PREHEADER]] ]
14 ; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], -1
15 ; CHECK-NEXT: [[CHECK:%.*]] = icmp slt i32 [[IV_NEXT]], [[IV]]
16 ; CHECK-NEXT: br i1 [[CHECK]], label [[GUARDED]], label [[FAIL:%.*]]
18 ; CHECK-NEXT: br i1 true, label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
19 ; CHECK: exit.loopexit:
20 ; CHECK-NEXT: br label [[EXIT]]
22 ; CHECK-NEXT: ret void
24 ; CHECK-NEXT: unreachable
27 %cond = icmp ne i32 %start, -2147483648
28 br i1 %cond, label %loop, label %exit
31 %iv = phi i32 [%start, %entry], [%iv.next, %guarded]
32 %iv.next = add i32 %iv, -1
33 %check = icmp slt i32 %iv.next, %iv
34 br i1 %check, label %guarded, label %fail
37 %loop.cond = icmp ne i32 %iv, -2147483648
38 br i1 %loop.cond, label %loop, label %exit
47 define void @test_unsigned(i32 %start) {
48 ; CHECK-LABEL: @test_unsigned(
50 ; CHECK-NEXT: [[COND:%.*]] = icmp ne i32 [[START:%.*]], 0
51 ; CHECK-NEXT: br i1 [[COND]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
52 ; CHECK: loop.preheader:
53 ; CHECK-NEXT: br label [[LOOP:%.*]]
55 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[GUARDED:%.*]] ], [ [[START]], [[LOOP_PREHEADER]] ]
56 ; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], -1
57 ; CHECK-NEXT: [[CHECK:%.*]] = icmp ult i32 [[IV_NEXT]], [[IV]]
58 ; CHECK-NEXT: br i1 [[CHECK]], label [[GUARDED]], label [[FAIL:%.*]]
60 ; CHECK-NEXT: br i1 true, label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
61 ; CHECK: exit.loopexit:
62 ; CHECK-NEXT: br label [[EXIT]]
64 ; CHECK-NEXT: ret void
66 ; CHECK-NEXT: unreachable
69 %cond = icmp ne i32 %start, 0
70 br i1 %cond, label %loop, label %exit
73 %iv = phi i32 [%start, %entry], [%iv.next, %guarded]
74 %iv.next = add i32 %iv, -1
75 %check = icmp ult i32 %iv.next, %iv
76 br i1 %check, label %guarded, label %fail
79 %loop.cond = icmp ne i32 %iv, 0
80 br i1 %loop.cond, label %loop, label %exit