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
5 ; FIXME: In all cases, x is from [0; 1000) and we cannot prove that x + 1 > x.
7 define void @test_sgt(i32 %x) {
8 ; CHECK-LABEL: @test_sgt(
10 ; CHECK-NEXT: [[PRECONDITION:%.*]] = icmp ult i32 [[X:%.*]], 1000
11 ; CHECK-NEXT: br i1 [[PRECONDITION]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
12 ; CHECK: loop.preheader:
13 ; CHECK-NEXT: br label [[LOOP:%.*]]
15 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[GUARDED:%.*]] ], [ [[X]], [[LOOP_PREHEADER]] ]
16 ; CHECK-NEXT: [[TMP:%.*]] = add i32 [[IV]], 1
17 ; CHECK-NEXT: [[GUARD:%.*]] = icmp sgt i32 [[TMP]], [[IV]]
18 ; CHECK-NEXT: br i1 [[GUARD]], label [[GUARDED]], label [[FAIL:%.*]]
20 ; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], -1
21 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV]], 0
22 ; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
23 ; CHECK: exit.loopexit:
24 ; CHECK-NEXT: br label [[EXIT]]
26 ; CHECK-NEXT: ret void
28 ; CHECK-NEXT: unreachable
31 %precondition = icmp ult i32 %x, 1000
32 br i1 %precondition, label %loop, label %exit
35 %iv = phi i32 [%x, %entry], [%iv.next, %guarded]
37 %guard = icmp sgt i32 %tmp, %iv
38 br i1 %guard, label %guarded, label %fail
41 %iv.next = add i32 %iv, -1
42 %cond = icmp eq i32 %iv, 0
43 br i1 %cond, label %loop, label %exit
52 define void @test_sge(i32 %x) {
53 ; CHECK-LABEL: @test_sge(
55 ; CHECK-NEXT: [[PRECONDITION:%.*]] = icmp ult i32 [[X:%.*]], 1000
56 ; CHECK-NEXT: br i1 [[PRECONDITION]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
57 ; CHECK: loop.preheader:
58 ; CHECK-NEXT: br label [[LOOP:%.*]]
60 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[GUARDED:%.*]] ], [ [[X]], [[LOOP_PREHEADER]] ]
61 ; CHECK-NEXT: [[TMP:%.*]] = add i32 [[IV]], 1
62 ; CHECK-NEXT: [[GUARD:%.*]] = icmp sge i32 [[TMP]], [[IV]]
63 ; CHECK-NEXT: br i1 [[GUARD]], label [[GUARDED]], label [[FAIL:%.*]]
65 ; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], -1
66 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV]], 0
67 ; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
68 ; CHECK: exit.loopexit:
69 ; CHECK-NEXT: br label [[EXIT]]
71 ; CHECK-NEXT: ret void
73 ; CHECK-NEXT: unreachable
76 %precondition = icmp ult i32 %x, 1000
77 br i1 %precondition, label %loop, label %exit
80 %iv = phi i32 [%x, %entry], [%iv.next, %guarded]
82 %guard = icmp sge i32 %tmp, %iv
83 br i1 %guard, label %guarded, label %fail
86 %iv.next = add i32 %iv, -1
87 %cond = icmp eq i32 %iv, 0
88 br i1 %cond, label %loop, label %exit
97 define void @test_ugt(i32 %x) {
98 ; CHECK-LABEL: @test_ugt(
100 ; CHECK-NEXT: [[PRECONDITION:%.*]] = icmp ult i32 [[X:%.*]], 1000
101 ; CHECK-NEXT: br i1 [[PRECONDITION]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
102 ; CHECK: loop.preheader:
103 ; CHECK-NEXT: br label [[LOOP:%.*]]
105 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[GUARDED:%.*]] ], [ [[X]], [[LOOP_PREHEADER]] ]
106 ; CHECK-NEXT: [[TMP:%.*]] = add i32 [[IV]], 1
107 ; CHECK-NEXT: [[GUARD:%.*]] = icmp ugt i32 [[TMP]], [[IV]]
108 ; CHECK-NEXT: br i1 [[GUARD]], label [[GUARDED]], label [[FAIL:%.*]]
110 ; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], -1
111 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV]], 0
112 ; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
113 ; CHECK: exit.loopexit:
114 ; CHECK-NEXT: br label [[EXIT]]
116 ; CHECK-NEXT: ret void
118 ; CHECK-NEXT: unreachable
121 %precondition = icmp ult i32 %x, 1000
122 br i1 %precondition, label %loop, label %exit
125 %iv = phi i32 [%x, %entry], [%iv.next, %guarded]
126 %tmp = add i32 %iv, 1
127 %guard = icmp ugt i32 %tmp, %iv
128 br i1 %guard, label %guarded, label %fail
131 %iv.next = add i32 %iv, -1
132 %cond = icmp eq i32 %iv, 0
133 br i1 %cond, label %loop, label %exit
143 define void @test_uge(i32 %x) {
144 ; CHECK-LABEL: @test_uge(
146 ; CHECK-NEXT: [[PRECONDITION:%.*]] = icmp ult i32 [[X:%.*]], 1000
147 ; CHECK-NEXT: br i1 [[PRECONDITION]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
148 ; CHECK: loop.preheader:
149 ; CHECK-NEXT: br label [[LOOP:%.*]]
151 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[GUARDED:%.*]] ], [ [[X]], [[LOOP_PREHEADER]] ]
152 ; CHECK-NEXT: [[TMP:%.*]] = add i32 [[IV]], 1
153 ; CHECK-NEXT: [[GUARD:%.*]] = icmp uge i32 [[TMP]], [[IV]]
154 ; CHECK-NEXT: br i1 [[GUARD]], label [[GUARDED]], label [[FAIL:%.*]]
156 ; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], -1
157 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV]], 0
158 ; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
159 ; CHECK: exit.loopexit:
160 ; CHECK-NEXT: br label [[EXIT]]
162 ; CHECK-NEXT: ret void
164 ; CHECK-NEXT: unreachable
167 %precondition = icmp ult i32 %x, 1000
168 br i1 %precondition, label %loop, label %exit
171 %iv = phi i32 [%x, %entry], [%iv.next, %guarded]
172 %tmp = add i32 %iv, 1
173 %guard = icmp uge i32 %tmp, %iv
174 br i1 %guard, label %guarded, label %fail
177 %iv.next = add i32 %iv, -1
178 %cond = icmp eq i32 %iv, 0
179 br i1 %cond, label %loop, label %exit