1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S < %s -passes=indvars | FileCheck %s
5 declare void @exit(i32 %code)
7 define void @test_01(ptr %p, i32 %shift) {
8 ; CHECK-LABEL: @test_01(
10 ; CHECK-NEXT: [[X:%.*]] = load i32, ptr [[P:%.*]], align 4, !range [[RNG0:![0-9]+]]
11 ; CHECK-NEXT: [[X_SHIFTED:%.*]] = lshr i32 [[X]], [[SHIFT:%.*]]
12 ; CHECK-NEXT: br label [[LOOP:%.*]]
14 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[BACKEDGE:%.*]] ]
15 ; CHECK-NEXT: [[LESS_THAN_SHIFTED:%.*]] = icmp ult i32 [[IV]], [[X_SHIFTED]]
16 ; CHECK-NEXT: br i1 [[LESS_THAN_SHIFTED]], label [[GUARDED:%.*]], label [[FAILURE:%.*]]
18 ; CHECK-NEXT: br i1 true, label [[BACKEDGE]], label [[NEVER_HAPPENS:%.*]]
20 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
21 ; CHECK-NEXT: [[LOOP_COND:%.*]] = call i1 @cond()
22 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[DONE:%.*]]
24 ; CHECK-NEXT: ret void
26 ; CHECK-NEXT: call void @exit(i32 1)
27 ; CHECK-NEXT: unreachable
28 ; CHECK: never_happens:
29 ; CHECK-NEXT: call void @exit(i32 0)
30 ; CHECK-NEXT: unreachable
33 %x = load i32, ptr %p, !range !0
34 %x.shifted = lshr i32 %x, %shift
38 %iv = phi i32 [0, %entry], [%iv.next, %backedge]
39 %less.than.shifted = icmp slt i32 %iv, %x.shifted
40 br i1 %less.than.shifted, label %guarded, label %failure
43 %less.than.x = icmp slt i32 %iv, %x
44 br i1 %less.than.x, label %backedge, label %never_happens
47 %iv.next = add nuw nsw i32 %iv, 1
48 %loop.cond = call i1 @cond()
49 br i1 %loop.cond, label %loop, label %done
55 call void @exit(i32 1)
59 call void @exit(i32 0)
63 define void @test_02(ptr %p, i32 %shift) {
64 ; CHECK-LABEL: @test_02(
66 ; CHECK-NEXT: [[X:%.*]] = load i32, ptr [[P:%.*]], align 4, !range [[RNG0]]
67 ; CHECK-NEXT: [[X_SHIFTED:%.*]] = lshr i32 [[X]], [[SHIFT:%.*]]
68 ; CHECK-NEXT: br label [[LOOP:%.*]]
70 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[BACKEDGE:%.*]] ]
71 ; CHECK-NEXT: [[LESS_THAN_SHIFTED:%.*]] = icmp ugt i32 [[X_SHIFTED]], [[IV]]
72 ; CHECK-NEXT: br i1 [[LESS_THAN_SHIFTED]], label [[GUARDED:%.*]], label [[FAILURE:%.*]]
74 ; CHECK-NEXT: br i1 true, label [[BACKEDGE]], label [[NEVER_HAPPENS:%.*]]
76 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
77 ; CHECK-NEXT: [[LOOP_COND:%.*]] = call i1 @cond()
78 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[DONE:%.*]]
80 ; CHECK-NEXT: ret void
82 ; CHECK-NEXT: call void @exit(i32 1)
83 ; CHECK-NEXT: unreachable
84 ; CHECK: never_happens:
85 ; CHECK-NEXT: call void @exit(i32 0)
86 ; CHECK-NEXT: unreachable
89 %x = load i32, ptr %p, !range !0
90 %x.shifted = lshr i32 %x, %shift
94 %iv = phi i32 [0, %entry], [%iv.next, %backedge]
95 %less.than.shifted = icmp sgt i32 %x.shifted, %iv
96 br i1 %less.than.shifted, label %guarded, label %failure
99 %less.than.x = icmp sgt i32 %x, %iv
100 br i1 %less.than.x, label %backedge, label %never_happens
103 %iv.next = add nuw nsw i32 %iv, 1
104 %loop.cond = call i1 @cond()
105 br i1 %loop.cond, label %loop, label %done
111 call void @exit(i32 1)
115 call void @exit(i32 0)
119 define void @test_03(ptr %p, i32 %shift) {
120 ; CHECK-LABEL: @test_03(
122 ; CHECK-NEXT: [[X:%.*]] = load i32, ptr [[P:%.*]], align 4, !range [[RNG0]]
123 ; CHECK-NEXT: [[X_SHIFTED:%.*]] = lshr i32 [[X]], [[SHIFT:%.*]]
124 ; CHECK-NEXT: br label [[LOOP:%.*]]
126 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[BACKEDGE:%.*]] ]
127 ; CHECK-NEXT: [[LESS_THAN_SHIFTED:%.*]] = icmp ult i32 [[IV]], [[X_SHIFTED]]
128 ; CHECK-NEXT: br i1 [[LESS_THAN_SHIFTED]], label [[GUARDED:%.*]], label [[FAILURE:%.*]]
130 ; CHECK-NEXT: br i1 true, label [[BACKEDGE]], label [[NEVER_HAPPENS:%.*]]
132 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
133 ; CHECK-NEXT: [[LOOP_COND:%.*]] = call i1 @cond()
134 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[DONE:%.*]]
136 ; CHECK-NEXT: ret void
138 ; CHECK-NEXT: call void @exit(i32 1)
139 ; CHECK-NEXT: unreachable
140 ; CHECK: never_happens:
141 ; CHECK-NEXT: call void @exit(i32 0)
142 ; CHECK-NEXT: unreachable
145 %x = load i32, ptr %p, !range !0
146 %x.shifted = lshr i32 %x, %shift
150 %iv = phi i32 [0, %entry], [%iv.next, %backedge]
151 %less.than.shifted = icmp ult i32 %iv, %x.shifted
152 br i1 %less.than.shifted, label %guarded, label %failure
155 %less.than.x = icmp ult i32 %iv, %x
156 br i1 %less.than.x, label %backedge, label %never_happens
159 %iv.next = add nuw nsw i32 %iv, 1
160 %loop.cond = call i1 @cond()
161 br i1 %loop.cond, label %loop, label %done
167 call void @exit(i32 1)
171 call void @exit(i32 0)
175 define void @test_04(ptr %p, i32 %shift) {
176 ; CHECK-LABEL: @test_04(
178 ; CHECK-NEXT: [[X:%.*]] = load i32, ptr [[P:%.*]], align 4, !range [[RNG0]]
179 ; CHECK-NEXT: [[X_SHIFTED:%.*]] = lshr i32 [[X]], [[SHIFT:%.*]]
180 ; CHECK-NEXT: br label [[LOOP:%.*]]
182 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[BACKEDGE:%.*]] ]
183 ; CHECK-NEXT: [[LESS_THAN_SHIFTED:%.*]] = icmp ugt i32 [[X_SHIFTED]], [[IV]]
184 ; CHECK-NEXT: br i1 [[LESS_THAN_SHIFTED]], label [[GUARDED:%.*]], label [[FAILURE:%.*]]
186 ; CHECK-NEXT: br i1 true, label [[BACKEDGE]], label [[NEVER_HAPPENS:%.*]]
188 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
189 ; CHECK-NEXT: [[LOOP_COND:%.*]] = call i1 @cond()
190 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[DONE:%.*]]
192 ; CHECK-NEXT: ret void
194 ; CHECK-NEXT: call void @exit(i32 1)
195 ; CHECK-NEXT: unreachable
196 ; CHECK: never_happens:
197 ; CHECK-NEXT: call void @exit(i32 0)
198 ; CHECK-NEXT: unreachable
201 %x = load i32, ptr %p, !range !0
202 %x.shifted = lshr i32 %x, %shift
206 %iv = phi i32 [0, %entry], [%iv.next, %backedge]
207 %less.than.shifted = icmp ugt i32 %x.shifted, %iv
208 br i1 %less.than.shifted, label %guarded, label %failure
211 %less.than.x = icmp ugt i32 %x, %iv
212 br i1 %less.than.x, label %backedge, label %never_happens
215 %iv.next = add nuw nsw i32 %iv, 1
216 %loop.cond = call i1 @cond()
217 br i1 %loop.cond, label %loop, label %done
223 call void @exit(i32 1)
227 call void @exit(i32 0)
231 !0 = !{i32 0, i32 2147483647}