1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=indvars -S | FileCheck %s
4 define void @test_signed(i32 %start) {
5 ; CHECK-LABEL: @test_signed(
7 ; CHECK-NEXT: [[COND:%.*]] = icmp ne i32 [[START:%.*]], -2147483648
8 ; CHECK-NEXT: br i1 [[COND]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
9 ; CHECK: loop.preheader:
10 ; CHECK-NEXT: br label [[LOOP:%.*]]
12 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[GUARDED:%.*]] ], [ [[START]], [[LOOP_PREHEADER]] ]
13 ; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], -1
14 ; CHECK-NEXT: [[CHECK:%.*]] = icmp slt i32 [[IV_NEXT]], [[IV]]
15 ; CHECK-NEXT: br i1 [[CHECK]], label [[GUARDED]], label [[FAIL:%.*]]
17 ; CHECK-NEXT: br i1 true, label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
18 ; CHECK: exit.loopexit:
19 ; CHECK-NEXT: br label [[EXIT]]
21 ; CHECK-NEXT: ret void
23 ; CHECK-NEXT: unreachable
26 %cond = icmp ne i32 %start, -2147483648
27 br i1 %cond, label %loop, label %exit
30 %iv = phi i32 [%start, %entry], [%iv.next, %guarded]
31 %iv.next = add i32 %iv, -1
32 %check = icmp slt i32 %iv.next, %iv
33 br i1 %check, label %guarded, label %fail
36 %loop.cond = icmp ne i32 %iv, -2147483648
37 br i1 %loop.cond, label %loop, label %exit
46 define void @test_unsigned(i32 %start) {
47 ; CHECK-LABEL: @test_unsigned(
49 ; CHECK-NEXT: [[COND:%.*]] = icmp ne i32 [[START:%.*]], 0
50 ; CHECK-NEXT: br i1 [[COND]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
51 ; CHECK: loop.preheader:
52 ; CHECK-NEXT: br label [[LOOP:%.*]]
54 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[GUARDED:%.*]] ], [ [[START]], [[LOOP_PREHEADER]] ]
55 ; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], -1
56 ; CHECK-NEXT: [[CHECK:%.*]] = icmp ult i32 [[IV_NEXT]], [[IV]]
57 ; CHECK-NEXT: br i1 [[CHECK]], label [[GUARDED]], label [[FAIL:%.*]]
59 ; CHECK-NEXT: br i1 true, label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
60 ; CHECK: exit.loopexit:
61 ; CHECK-NEXT: br label [[EXIT]]
63 ; CHECK-NEXT: ret void
65 ; CHECK-NEXT: unreachable
68 %cond = icmp ne i32 %start, 0
69 br i1 %cond, label %loop, label %exit
72 %iv = phi i32 [%start, %entry], [%iv.next, %guarded]
73 %iv.next = add i32 %iv, -1
74 %check = icmp ult i32 %iv.next, %iv
75 br i1 %check, label %guarded, label %fail
78 %loop.cond = icmp ne i32 %iv, 0
79 br i1 %loop.cond, label %loop, label %exit