1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=indvars -S < %s | FileCheck %s
4 ; FIXME: In all cases, x is from [0; 1000) and we cannot prove that x + 1 > x.
6 define void @test_sgt(i32 %x) {
7 ; CHECK-LABEL: @test_sgt(
9 ; CHECK-NEXT: [[PRECONDITION:%.*]] = icmp ult i32 [[X:%.*]], 1000
10 ; CHECK-NEXT: br i1 [[PRECONDITION]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
11 ; CHECK: loop.preheader:
12 ; CHECK-NEXT: br label [[LOOP:%.*]]
14 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[GUARDED:%.*]] ], [ [[X]], [[LOOP_PREHEADER]] ]
15 ; CHECK-NEXT: [[TMP:%.*]] = add nsw i32 [[IV]], 1
16 ; CHECK-NEXT: [[GUARD:%.*]] = icmp sgt i32 [[TMP]], [[IV]]
17 ; CHECK-NEXT: br i1 [[GUARD]], label [[GUARDED]], label [[FAIL:%.*]]
19 ; CHECK-NEXT: [[IV_NEXT]] = add nsw i32 [[IV]], -1
20 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV]], 0
21 ; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
22 ; CHECK: exit.loopexit:
23 ; CHECK-NEXT: br label [[EXIT]]
25 ; CHECK-NEXT: ret void
27 ; CHECK-NEXT: unreachable
30 %precondition = icmp ult i32 %x, 1000
31 br i1 %precondition, label %loop, label %exit
34 %iv = phi i32 [%x, %entry], [%iv.next, %guarded]
36 %guard = icmp sgt i32 %tmp, %iv
37 br i1 %guard, label %guarded, label %fail
40 %iv.next = add i32 %iv, -1
41 %cond = icmp eq i32 %iv, 0
42 br i1 %cond, label %loop, label %exit
51 define void @test_sge(i32 %x) {
52 ; CHECK-LABEL: @test_sge(
54 ; CHECK-NEXT: [[PRECONDITION:%.*]] = icmp ult i32 [[X:%.*]], 1000
55 ; CHECK-NEXT: br i1 [[PRECONDITION]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
56 ; CHECK: loop.preheader:
57 ; CHECK-NEXT: br label [[LOOP:%.*]]
59 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[GUARDED:%.*]] ], [ [[X]], [[LOOP_PREHEADER]] ]
60 ; CHECK-NEXT: [[TMP:%.*]] = add nsw i32 [[IV]], 1
61 ; CHECK-NEXT: [[GUARD:%.*]] = icmp sge i32 [[TMP]], [[IV]]
62 ; CHECK-NEXT: br i1 [[GUARD]], label [[GUARDED]], label [[FAIL:%.*]]
64 ; CHECK-NEXT: [[IV_NEXT]] = add nsw i32 [[IV]], -1
65 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV]], 0
66 ; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
67 ; CHECK: exit.loopexit:
68 ; CHECK-NEXT: br label [[EXIT]]
70 ; CHECK-NEXT: ret void
72 ; CHECK-NEXT: unreachable
75 %precondition = icmp ult i32 %x, 1000
76 br i1 %precondition, label %loop, label %exit
79 %iv = phi i32 [%x, %entry], [%iv.next, %guarded]
81 %guard = icmp sge i32 %tmp, %iv
82 br i1 %guard, label %guarded, label %fail
85 %iv.next = add i32 %iv, -1
86 %cond = icmp eq i32 %iv, 0
87 br i1 %cond, label %loop, label %exit
96 define void @test_ugt(i32 %x) {
97 ; CHECK-LABEL: @test_ugt(
99 ; CHECK-NEXT: [[PRECONDITION:%.*]] = icmp ult i32 [[X:%.*]], 1000
100 ; CHECK-NEXT: br i1 [[PRECONDITION]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
101 ; CHECK: loop.preheader:
102 ; CHECK-NEXT: br label [[LOOP:%.*]]
104 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[GUARDED:%.*]] ], [ [[X]], [[LOOP_PREHEADER]] ]
105 ; CHECK-NEXT: [[TMP:%.*]] = add nsw i32 [[IV]], 1
106 ; CHECK-NEXT: [[GUARD:%.*]] = icmp ugt i32 [[TMP]], [[IV]]
107 ; CHECK-NEXT: br i1 [[GUARD]], label [[GUARDED]], label [[FAIL:%.*]]
109 ; CHECK-NEXT: [[IV_NEXT]] = add nsw i32 [[IV]], -1
110 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV]], 0
111 ; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
112 ; CHECK: exit.loopexit:
113 ; CHECK-NEXT: br label [[EXIT]]
115 ; CHECK-NEXT: ret void
117 ; CHECK-NEXT: unreachable
120 %precondition = icmp ult i32 %x, 1000
121 br i1 %precondition, label %loop, label %exit
124 %iv = phi i32 [%x, %entry], [%iv.next, %guarded]
125 %tmp = add i32 %iv, 1
126 %guard = icmp ugt i32 %tmp, %iv
127 br i1 %guard, label %guarded, label %fail
130 %iv.next = add i32 %iv, -1
131 %cond = icmp eq i32 %iv, 0
132 br i1 %cond, label %loop, label %exit
142 define void @test_uge(i32 %x) {
143 ; CHECK-LABEL: @test_uge(
145 ; CHECK-NEXT: [[PRECONDITION:%.*]] = icmp ult i32 [[X:%.*]], 1000
146 ; CHECK-NEXT: br i1 [[PRECONDITION]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
147 ; CHECK: loop.preheader:
148 ; CHECK-NEXT: br label [[LOOP:%.*]]
150 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[GUARDED:%.*]] ], [ [[X]], [[LOOP_PREHEADER]] ]
151 ; CHECK-NEXT: [[TMP:%.*]] = add nsw i32 [[IV]], 1
152 ; CHECK-NEXT: [[GUARD:%.*]] = icmp uge i32 [[TMP]], [[IV]]
153 ; CHECK-NEXT: br i1 [[GUARD]], label [[GUARDED]], label [[FAIL:%.*]]
155 ; CHECK-NEXT: [[IV_NEXT]] = add nsw i32 [[IV]], -1
156 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV]], 0
157 ; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
158 ; CHECK: exit.loopexit:
159 ; CHECK-NEXT: br label [[EXIT]]
161 ; CHECK-NEXT: ret void
163 ; CHECK-NEXT: unreachable
166 %precondition = icmp ult i32 %x, 1000
167 br i1 %precondition, label %loop, label %exit
170 %iv = phi i32 [%x, %entry], [%iv.next, %guarded]
171 %tmp = add i32 %iv, 1
172 %guard = icmp uge i32 %tmp, %iv
173 br i1 %guard, label %guarded, label %fail
176 %iv.next = add i32 %iv, -1
177 %cond = icmp eq i32 %iv, 0
178 br i1 %cond, label %loop, label %exit