1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -indvars -S < %s | FileCheck %s
3 ; RUN: opt -passes=indvars -S < %s | FileCheck %s
7 define void @test_01(i32 %x) {
8 ; CHECK-LABEL: @test_01(
10 ; CHECK-NEXT: br i1 true, label [[LOOP_1_PREHEADER:%.*]], label [[LOOP_2_PREHEADER:%.*]]
11 ; CHECK: loop.2.preheader:
12 ; CHECK-NEXT: br label [[LOOP_2:%.*]]
13 ; CHECK: loop.1.preheader:
14 ; CHECK-NEXT: br label [[LOOP_1:%.*]]
16 ; CHECK-NEXT: [[IV_1:%.*]] = phi i32 [ [[IV_NEXT_1:%.*]], [[GUARDED_1:%.*]] ], [ 0, [[LOOP_1_PREHEADER]] ]
17 ; CHECK-NEXT: [[CHECK_1:%.*]] = icmp slt i32 [[IV_1]], [[X:%.*]]
18 ; CHECK-NEXT: br i1 [[CHECK_1]], label [[GUARDED_1]], label [[FAIL_LOOPEXIT:%.*]]
20 ; CHECK-NEXT: [[IV_NEXT_1]] = add nuw i32 [[IV_1]], 1
21 ; CHECK-NEXT: [[LOOP_COND_1:%.*]] = call i1 @cond()
22 ; CHECK-NEXT: br i1 [[LOOP_COND_1]], label [[LOOP_1]], label [[EXIT_LOOPEXIT:%.*]]
24 ; CHECK-NEXT: br i1 true, label [[GUARDED_2:%.*]], label [[FAIL_LOOPEXIT1:%.*]]
26 ; CHECK-NEXT: [[LOOP_COND_2:%.*]] = call i1 @cond()
27 ; CHECK-NEXT: br i1 [[LOOP_COND_2]], label [[LOOP_2]], label [[EXIT_LOOPEXIT2:%.*]]
28 ; CHECK: exit.loopexit:
29 ; CHECK-NEXT: br label [[EXIT:%.*]]
30 ; CHECK: exit.loopexit2:
31 ; CHECK-NEXT: br label [[EXIT]]
33 ; CHECK-NEXT: ret void
34 ; CHECK: fail.loopexit:
35 ; CHECK-NEXT: br label [[FAIL:%.*]]
36 ; CHECK: fail.loopexit1:
37 ; CHECK-NEXT: br label [[FAIL]]
39 ; CHECK-NEXT: unreachable
42 br i1 true, label %loop.1, label %loop.2
45 %iv.1 = phi i32 [0, %entry], [%iv.next.1, %guarded.1]
46 %check.1 = icmp slt i32 %iv.1, %x
47 br i1 %check.1, label %guarded.1, label %fail
50 %iv.next.1 = add i32 %iv.1, 1
51 %loop.cond.1 = call i1 @cond()
52 br i1 %loop.cond.1, label %loop.1, label %exit
55 %iv.2 = phi i32 [0, %entry], [%iv.next.2, %guarded.2]
56 %check.2 = icmp slt i32 %iv.2, %x
57 br i1 %check.2, label %guarded.2, label %fail
60 %iv.next.2 = add i32 %iv.2, 1
61 %loop.cond.2 = call i1 @cond()
62 br i1 %loop.cond.2, label %loop.2, label %exit
71 define void @test_02(i32 %x) {
72 ; CHECK-LABEL: @test_02(
74 ; CHECK-NEXT: br i1 false, label [[LOOP_1_PREHEADER:%.*]], label [[LOOP_2_PREHEADER:%.*]]
75 ; CHECK: loop.2.preheader:
76 ; CHECK-NEXT: br label [[LOOP_2:%.*]]
77 ; CHECK: loop.1.preheader:
78 ; CHECK-NEXT: br label [[LOOP_1:%.*]]
80 ; CHECK-NEXT: br i1 true, label [[GUARDED_1:%.*]], label [[FAIL_LOOPEXIT:%.*]]
82 ; CHECK-NEXT: [[LOOP_COND_1:%.*]] = call i1 @cond()
83 ; CHECK-NEXT: br i1 [[LOOP_COND_1]], label [[LOOP_1]], label [[EXIT_LOOPEXIT:%.*]]
85 ; CHECK-NEXT: [[IV_2:%.*]] = phi i32 [ [[IV_NEXT_2:%.*]], [[GUARDED_2:%.*]] ], [ 0, [[LOOP_2_PREHEADER]] ]
86 ; CHECK-NEXT: [[CHECK_2:%.*]] = icmp slt i32 [[IV_2]], [[X:%.*]]
87 ; CHECK-NEXT: br i1 [[CHECK_2]], label [[GUARDED_2]], label [[FAIL_LOOPEXIT1:%.*]]
89 ; CHECK-NEXT: [[IV_NEXT_2]] = add nuw i32 [[IV_2]], 1
90 ; CHECK-NEXT: [[LOOP_COND_2:%.*]] = call i1 @cond()
91 ; CHECK-NEXT: br i1 [[LOOP_COND_2]], label [[LOOP_2]], label [[EXIT_LOOPEXIT2:%.*]]
92 ; CHECK: exit.loopexit:
93 ; CHECK-NEXT: br label [[EXIT:%.*]]
94 ; CHECK: exit.loopexit2:
95 ; CHECK-NEXT: br label [[EXIT]]
97 ; CHECK-NEXT: ret void
98 ; CHECK: fail.loopexit:
99 ; CHECK-NEXT: br label [[FAIL:%.*]]
100 ; CHECK: fail.loopexit1:
101 ; CHECK-NEXT: br label [[FAIL]]
103 ; CHECK-NEXT: unreachable
106 br i1 false, label %loop.1, label %loop.2
109 %iv.1 = phi i32 [0, %entry], [%iv.next.1, %guarded.1]
110 %check.1 = icmp slt i32 %iv.1, %x
111 br i1 %check.1, label %guarded.1, label %fail
114 %iv.next.1 = add i32 %iv.1, 1
115 %loop.cond.1 = call i1 @cond()
116 br i1 %loop.cond.1, label %loop.1, label %exit
119 %iv.2 = phi i32 [0, %entry], [%iv.next.2, %guarded.2]
120 %check.2 = icmp slt i32 %iv.2, %x
121 br i1 %check.2, label %guarded.2, label %fail
124 %iv.next.2 = add i32 %iv.2, 1
125 %loop.cond.2 = call i1 @cond()
126 br i1 %loop.cond.2, label %loop.2, label %exit