1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=indvars -S < %s | FileCheck %s
6 define void @test_01(i32 %x) {
7 ; CHECK-LABEL: @test_01(
9 ; CHECK-NEXT: br i1 true, label [[LOOP_1_PREHEADER:%.*]], label [[LOOP_2_PREHEADER:%.*]]
10 ; CHECK: loop.2.preheader:
11 ; CHECK-NEXT: br label [[LOOP_2:%.*]]
12 ; CHECK: loop.1.preheader:
13 ; CHECK-NEXT: br label [[LOOP_1:%.*]]
15 ; CHECK-NEXT: [[IV_1:%.*]] = phi i32 [ [[IV_NEXT_1:%.*]], [[GUARDED_1:%.*]] ], [ 0, [[LOOP_1_PREHEADER]] ]
16 ; CHECK-NEXT: [[CHECK_1:%.*]] = icmp slt i32 [[IV_1]], [[X:%.*]]
17 ; CHECK-NEXT: br i1 [[CHECK_1]], label [[GUARDED_1]], label [[FAIL_LOOPEXIT:%.*]]
19 ; CHECK-NEXT: [[IV_NEXT_1]] = add nuw nsw i32 [[IV_1]], 1
20 ; CHECK-NEXT: [[LOOP_COND_1:%.*]] = call i1 @cond()
21 ; CHECK-NEXT: br i1 [[LOOP_COND_1]], label [[LOOP_1]], label [[EXIT_LOOPEXIT:%.*]]
23 ; CHECK-NEXT: br i1 true, label [[GUARDED_2:%.*]], label [[FAIL_LOOPEXIT1:%.*]]
25 ; CHECK-NEXT: [[LOOP_COND_2:%.*]] = call i1 @cond()
26 ; CHECK-NEXT: br i1 [[LOOP_COND_2]], label [[LOOP_2]], label [[EXIT_LOOPEXIT2:%.*]]
27 ; CHECK: exit.loopexit:
28 ; CHECK-NEXT: br label [[EXIT:%.*]]
29 ; CHECK: exit.loopexit2:
30 ; CHECK-NEXT: br label [[EXIT]]
32 ; CHECK-NEXT: ret void
33 ; CHECK: fail.loopexit:
34 ; CHECK-NEXT: br label [[FAIL:%.*]]
35 ; CHECK: fail.loopexit1:
36 ; CHECK-NEXT: br label [[FAIL]]
38 ; CHECK-NEXT: unreachable
41 br i1 true, label %loop.1, label %loop.2
44 %iv.1 = phi i32 [0, %entry], [%iv.next.1, %guarded.1]
45 %check.1 = icmp slt i32 %iv.1, %x
46 br i1 %check.1, label %guarded.1, label %fail
49 %iv.next.1 = add i32 %iv.1, 1
50 %loop.cond.1 = call i1 @cond()
51 br i1 %loop.cond.1, label %loop.1, label %exit
54 %iv.2 = phi i32 [0, %entry], [%iv.next.2, %guarded.2]
55 %check.2 = icmp slt i32 %iv.2, %x
56 br i1 %check.2, label %guarded.2, label %fail
59 %iv.next.2 = add i32 %iv.2, 1
60 %loop.cond.2 = call i1 @cond()
61 br i1 %loop.cond.2, label %loop.2, label %exit
70 define void @test_02(i32 %x) {
71 ; CHECK-LABEL: @test_02(
73 ; CHECK-NEXT: br i1 false, label [[LOOP_1_PREHEADER:%.*]], label [[LOOP_2_PREHEADER:%.*]]
74 ; CHECK: loop.2.preheader:
75 ; CHECK-NEXT: br label [[LOOP_2:%.*]]
76 ; CHECK: loop.1.preheader:
77 ; CHECK-NEXT: br label [[LOOP_1:%.*]]
79 ; CHECK-NEXT: br i1 true, label [[GUARDED_1:%.*]], label [[FAIL_LOOPEXIT:%.*]]
81 ; CHECK-NEXT: [[LOOP_COND_1:%.*]] = call i1 @cond()
82 ; CHECK-NEXT: br i1 [[LOOP_COND_1]], label [[LOOP_1]], label [[EXIT_LOOPEXIT:%.*]]
84 ; CHECK-NEXT: [[IV_2:%.*]] = phi i32 [ [[IV_NEXT_2:%.*]], [[GUARDED_2:%.*]] ], [ 0, [[LOOP_2_PREHEADER]] ]
85 ; CHECK-NEXT: [[CHECK_2:%.*]] = icmp slt i32 [[IV_2]], [[X:%.*]]
86 ; CHECK-NEXT: br i1 [[CHECK_2]], label [[GUARDED_2]], label [[FAIL_LOOPEXIT1:%.*]]
88 ; CHECK-NEXT: [[IV_NEXT_2]] = add nuw nsw i32 [[IV_2]], 1
89 ; CHECK-NEXT: [[LOOP_COND_2:%.*]] = call i1 @cond()
90 ; CHECK-NEXT: br i1 [[LOOP_COND_2]], label [[LOOP_2]], label [[EXIT_LOOPEXIT2:%.*]]
91 ; CHECK: exit.loopexit:
92 ; CHECK-NEXT: br label [[EXIT:%.*]]
93 ; CHECK: exit.loopexit2:
94 ; CHECK-NEXT: br label [[EXIT]]
96 ; CHECK-NEXT: ret void
97 ; CHECK: fail.loopexit:
98 ; CHECK-NEXT: br label [[FAIL:%.*]]
99 ; CHECK: fail.loopexit1:
100 ; CHECK-NEXT: br label [[FAIL]]
102 ; CHECK-NEXT: unreachable
105 br i1 false, label %loop.1, label %loop.2
108 %iv.1 = phi i32 [0, %entry], [%iv.next.1, %guarded.1]
109 %check.1 = icmp slt i32 %iv.1, %x
110 br i1 %check.1, label %guarded.1, label %fail
113 %iv.next.1 = add i32 %iv.1, 1
114 %loop.cond.1 = call i1 @cond()
115 br i1 %loop.cond.1, label %loop.1, label %exit
118 %iv.2 = phi i32 [0, %entry], [%iv.next.2, %guarded.2]
119 %check.2 = icmp slt i32 %iv.2, %x
120 br i1 %check.2, label %guarded.2, label %fail
123 %iv.next.2 = add i32 %iv.2, 1
124 %loop.cond.2 = call i1 @cond()
125 br i1 %loop.cond.2, label %loop.2, label %exit