1*cee313d2SEric Christopher; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2*cee313d2SEric Christopher; RUN: opt -S -loop-predication < %s 2>&1 | FileCheck %s
3*cee313d2SEric Christopher; RUN: opt -S -passes='require<scalar-evolution>,loop(loop-predication)' < %s 2>&1 | FileCheck %s
4*cee313d2SEric Christopher
5*cee313d2SEric Christopherdeclare void @llvm.experimental.guard(i1, ...)
6*cee313d2SEric Christopher
7*cee313d2SEric Christopherdefine i32 @unsigned_loop_0_to_n_ult_check(i32* %array, i32 %length, i32 %n) {
8*cee313d2SEric Christopher; CHECK-LABEL: @unsigned_loop_0_to_n_ult_check(
9*cee313d2SEric Christopher; CHECK-NEXT:  entry:
10*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
11*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
12*cee313d2SEric Christopher; CHECK:       loop.preheader:
13*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = icmp ule i32 [[N]], [[LENGTH:%.*]]
14*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH]]
15*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
16*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
17*cee313d2SEric Christopher; CHECK:       loop:
18*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
19*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
20*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP2]], i32 9) [ "deopt"() ]
21*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
22*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
23*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
24*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
25*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nuw i32 [[I]], 1
26*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp ult i32 [[I_NEXT]], [[N]]
27*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
28*cee313d2SEric Christopher; CHECK:       exit.loopexit:
29*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
30*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
31*cee313d2SEric Christopher; CHECK:       exit:
32*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
33*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
34*cee313d2SEric Christopher;
35*cee313d2SEric Christopherentry:
36*cee313d2SEric Christopher  %tmp5 = icmp eq i32 %n, 0
37*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
38*cee313d2SEric Christopher
39*cee313d2SEric Christopherloop.preheader:
40*cee313d2SEric Christopher  br label %loop
41*cee313d2SEric Christopher
42*cee313d2SEric Christopherloop:
43*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
44*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
45*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %i, %length
46*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
47*cee313d2SEric Christopher
48*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
49*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
50*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
51*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
52*cee313d2SEric Christopher
53*cee313d2SEric Christopher  %i.next = add nuw i32 %i, 1
54*cee313d2SEric Christopher  %continue = icmp ult i32 %i.next, %n
55*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
56*cee313d2SEric Christopher
57*cee313d2SEric Christopherexit:
58*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
59*cee313d2SEric Christopher  ret i32 %result
60*cee313d2SEric Christopher}
61*cee313d2SEric Christopher
62*cee313d2SEric Christopherdefine i32 @unsigned_loop_0_to_n_ule_latch_ult_check(i32* %array, i32 %length, i32 %n) {
63*cee313d2SEric Christopher; CHECK-LABEL: @unsigned_loop_0_to_n_ule_latch_ult_check(
64*cee313d2SEric Christopher; CHECK-NEXT:  entry:
65*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
66*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
67*cee313d2SEric Christopher; CHECK:       loop.preheader:
68*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = icmp ult i32 [[N]], [[LENGTH:%.*]]
69*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH]]
70*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
71*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
72*cee313d2SEric Christopher; CHECK:       loop:
73*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
74*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
75*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP2]], i32 9) [ "deopt"() ]
76*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
77*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
78*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
79*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
80*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nuw i32 [[I]], 1
81*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp ule i32 [[I_NEXT]], [[N]]
82*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
83*cee313d2SEric Christopher; CHECK:       exit.loopexit:
84*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
85*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
86*cee313d2SEric Christopher; CHECK:       exit:
87*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
88*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
89*cee313d2SEric Christopher;
90*cee313d2SEric Christopherentry:
91*cee313d2SEric Christopher  %tmp5 = icmp eq i32 %n, 0
92*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
93*cee313d2SEric Christopher
94*cee313d2SEric Christopherloop.preheader:
95*cee313d2SEric Christopher  br label %loop
96*cee313d2SEric Christopher
97*cee313d2SEric Christopherloop:
98*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
99*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
100*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %i, %length
101*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
102*cee313d2SEric Christopher
103*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
104*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
105*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
106*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
107*cee313d2SEric Christopher
108*cee313d2SEric Christopher  %i.next = add nuw i32 %i, 1
109*cee313d2SEric Christopher  %continue = icmp ule i32 %i.next, %n
110*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
111*cee313d2SEric Christopher
112*cee313d2SEric Christopherexit:
113*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
114*cee313d2SEric Christopher  ret i32 %result
115*cee313d2SEric Christopher}
116*cee313d2SEric Christopher
117*cee313d2SEric Christopherdefine i32 @unsigned_loop_0_to_n_ugt_check(i32* %array, i32 %length, i32 %n) {
118*cee313d2SEric Christopher; CHECK-LABEL: @unsigned_loop_0_to_n_ugt_check(
119*cee313d2SEric Christopher; CHECK-NEXT:  entry:
120*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
121*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
122*cee313d2SEric Christopher; CHECK:       loop.preheader:
123*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = icmp ule i32 [[N]], [[LENGTH:%.*]]
124*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH]]
125*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
126*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
127*cee313d2SEric Christopher; CHECK:       loop:
128*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
129*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
130*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP2]], i32 9) [ "deopt"() ]
131*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
132*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
133*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
134*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
135*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nuw i32 [[I]], 1
136*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp ult i32 [[I_NEXT]], [[N]]
137*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
138*cee313d2SEric Christopher; CHECK:       exit.loopexit:
139*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
140*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
141*cee313d2SEric Christopher; CHECK:       exit:
142*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
143*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
144*cee313d2SEric Christopher;
145*cee313d2SEric Christopherentry:
146*cee313d2SEric Christopher  %tmp5 = icmp eq i32 %n, 0
147*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
148*cee313d2SEric Christopher
149*cee313d2SEric Christopherloop.preheader:
150*cee313d2SEric Christopher  br label %loop
151*cee313d2SEric Christopher
152*cee313d2SEric Christopherloop:
153*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
154*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
155*cee313d2SEric Christopher  %within.bounds = icmp ugt i32 %length, %i
156*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
157*cee313d2SEric Christopher
158*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
159*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
160*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
161*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
162*cee313d2SEric Christopher
163*cee313d2SEric Christopher  %i.next = add nuw i32 %i, 1
164*cee313d2SEric Christopher  %continue = icmp ult i32 %i.next, %n
165*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
166*cee313d2SEric Christopher
167*cee313d2SEric Christopherexit:
168*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
169*cee313d2SEric Christopher  ret i32 %result
170*cee313d2SEric Christopher}
171*cee313d2SEric Christopher
172*cee313d2SEric Christopherdefine i32 @signed_loop_0_to_n_ult_check(i32* %array, i32 %length, i32 %n) {
173*cee313d2SEric Christopher; CHECK-LABEL: @signed_loop_0_to_n_ult_check(
174*cee313d2SEric Christopher; CHECK-NEXT:  entry:
175*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
176*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
177*cee313d2SEric Christopher; CHECK:       loop.preheader:
178*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = icmp sle i32 [[N]], [[LENGTH:%.*]]
179*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH]]
180*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
181*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
182*cee313d2SEric Christopher; CHECK:       loop:
183*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
184*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
185*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP2]], i32 9) [ "deopt"() ]
186*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
187*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
188*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
189*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
190*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nuw i32 [[I]], 1
191*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp slt i32 [[I_NEXT]], [[N]]
192*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
193*cee313d2SEric Christopher; CHECK:       exit.loopexit:
194*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
195*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
196*cee313d2SEric Christopher; CHECK:       exit:
197*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
198*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
199*cee313d2SEric Christopher;
200*cee313d2SEric Christopherentry:
201*cee313d2SEric Christopher  %tmp5 = icmp sle i32 %n, 0
202*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
203*cee313d2SEric Christopher
204*cee313d2SEric Christopherloop.preheader:
205*cee313d2SEric Christopher  br label %loop
206*cee313d2SEric Christopher
207*cee313d2SEric Christopherloop:
208*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
209*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
210*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %i, %length
211*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
212*cee313d2SEric Christopher
213*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
214*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
215*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
216*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
217*cee313d2SEric Christopher
218*cee313d2SEric Christopher  %i.next = add nuw i32 %i, 1
219*cee313d2SEric Christopher  %continue = icmp slt i32 %i.next, %n
220*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
221*cee313d2SEric Christopher
222*cee313d2SEric Christopherexit:
223*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
224*cee313d2SEric Christopher  ret i32 %result
225*cee313d2SEric Christopher}
226*cee313d2SEric Christopher
227*cee313d2SEric Christopherdefine i32 @signed_loop_0_to_n_ult_check_length_range_known(i32* %array, i32* %length.ptr, i32 %n) {
228*cee313d2SEric Christopher; CHECK-LABEL: @signed_loop_0_to_n_ult_check_length_range_known(
229*cee313d2SEric Christopher; CHECK-NEXT:  entry:
230*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
231*cee313d2SEric Christopher; CHECK-NEXT:    [[LENGTH:%.*]] = load i32, i32* [[LENGTH_PTR:%.*]], !range !0
232*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
233*cee313d2SEric Christopher; CHECK:       loop.preheader:
234*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = icmp sle i32 [[N]], [[LENGTH]]
235*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = and i1 true, [[TMP0]]
236*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
237*cee313d2SEric Christopher; CHECK:       loop:
238*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
239*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
240*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP1]], i32 9) [ "deopt"() ]
241*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
242*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
243*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
244*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
245*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nuw i32 [[I]], 1
246*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp slt i32 [[I_NEXT]], [[N]]
247*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
248*cee313d2SEric Christopher; CHECK:       exit.loopexit:
249*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
250*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
251*cee313d2SEric Christopher; CHECK:       exit:
252*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
253*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
254*cee313d2SEric Christopher;
255*cee313d2SEric Christopherentry:
256*cee313d2SEric Christopher  %tmp5 = icmp sle i32 %n, 0
257*cee313d2SEric Christopher  %length = load i32, i32* %length.ptr, !range !{i32 1, i32 2147483648}
258*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
259*cee313d2SEric Christopher
260*cee313d2SEric Christopherloop.preheader:
261*cee313d2SEric Christopher  br label %loop
262*cee313d2SEric Christopher
263*cee313d2SEric Christopherloop:
264*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
265*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
266*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %i, %length
267*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
268*cee313d2SEric Christopher
269*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
270*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
271*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
272*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
273*cee313d2SEric Christopher
274*cee313d2SEric Christopher  %i.next = add nuw i32 %i, 1
275*cee313d2SEric Christopher  %continue = icmp slt i32 %i.next, %n
276*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
277*cee313d2SEric Christopher
278*cee313d2SEric Christopherexit:
279*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
280*cee313d2SEric Christopher  ret i32 %result
281*cee313d2SEric Christopher}
282*cee313d2SEric Christopher
283*cee313d2SEric Christopherdefine i32 @signed_loop_0_to_n_inverse_latch_predicate(i32* %array, i32 %length, i32 %n) {
284*cee313d2SEric Christopher; CHECK-LABEL: @signed_loop_0_to_n_inverse_latch_predicate(
285*cee313d2SEric Christopher; CHECK-NEXT:  entry:
286*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
287*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
288*cee313d2SEric Christopher; CHECK:       loop.preheader:
289*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = icmp slt i32 [[N]], [[LENGTH:%.*]]
290*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH]]
291*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
292*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
293*cee313d2SEric Christopher; CHECK:       loop:
294*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
295*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
296*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP2]], i32 9) [ "deopt"() ]
297*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
298*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
299*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
300*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
301*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nuw i32 [[I]], 1
302*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp sgt i32 [[I_NEXT]], [[N]]
303*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[EXIT_LOOPEXIT:%.*]], label [[LOOP]]
304*cee313d2SEric Christopher; CHECK:       exit.loopexit:
305*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
306*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
307*cee313d2SEric Christopher; CHECK:       exit:
308*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
309*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
310*cee313d2SEric Christopher;
311*cee313d2SEric Christopherentry:
312*cee313d2SEric Christopher  %tmp5 = icmp sle i32 %n, 0
313*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
314*cee313d2SEric Christopher
315*cee313d2SEric Christopherloop.preheader:
316*cee313d2SEric Christopher  br label %loop
317*cee313d2SEric Christopher
318*cee313d2SEric Christopherloop:
319*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
320*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
321*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %i, %length
322*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
323*cee313d2SEric Christopher
324*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
325*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
326*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
327*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
328*cee313d2SEric Christopher
329*cee313d2SEric Christopher  %i.next = add nuw i32 %i, 1
330*cee313d2SEric Christopher  %continue = icmp sgt i32 %i.next, %n
331*cee313d2SEric Christopher  br i1 %continue, label %exit, label %loop
332*cee313d2SEric Christopher
333*cee313d2SEric Christopherexit:
334*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
335*cee313d2SEric Christopher  ret i32 %result
336*cee313d2SEric Christopher}
337*cee313d2SEric Christopher
338*cee313d2SEric Christopherdefine i32 @signed_loop_0_to_n_sle_latch_ult_check(i32* %array, i32 %length, i32 %n) {
339*cee313d2SEric Christopher; CHECK-LABEL: @signed_loop_0_to_n_sle_latch_ult_check(
340*cee313d2SEric Christopher; CHECK-NEXT:  entry:
341*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
342*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
343*cee313d2SEric Christopher; CHECK:       loop.preheader:
344*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = icmp slt i32 [[N]], [[LENGTH:%.*]]
345*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH]]
346*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
347*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
348*cee313d2SEric Christopher; CHECK:       loop:
349*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
350*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
351*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP2]], i32 9) [ "deopt"() ]
352*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
353*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
354*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
355*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
356*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nuw i32 [[I]], 1
357*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp sle i32 [[I_NEXT]], [[N]]
358*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
359*cee313d2SEric Christopher; CHECK:       exit.loopexit:
360*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
361*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
362*cee313d2SEric Christopher; CHECK:       exit:
363*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
364*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
365*cee313d2SEric Christopher;
366*cee313d2SEric Christopherentry:
367*cee313d2SEric Christopher  %tmp5 = icmp sle i32 %n, 0
368*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
369*cee313d2SEric Christopher
370*cee313d2SEric Christopherloop.preheader:
371*cee313d2SEric Christopher  br label %loop
372*cee313d2SEric Christopher
373*cee313d2SEric Christopherloop:
374*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
375*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
376*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %i, %length
377*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
378*cee313d2SEric Christopher
379*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
380*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
381*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
382*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
383*cee313d2SEric Christopher
384*cee313d2SEric Christopher  %i.next = add nuw i32 %i, 1
385*cee313d2SEric Christopher  %continue = icmp sle i32 %i.next, %n
386*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
387*cee313d2SEric Christopher
388*cee313d2SEric Christopherexit:
389*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
390*cee313d2SEric Christopher  ret i32 %result
391*cee313d2SEric Christopher}
392*cee313d2SEric Christopher
393*cee313d2SEric Christopherdefine i32 @signed_loop_0_to_n_preincrement_latch_check(i32* %array, i32 %length, i32 %n) {
394*cee313d2SEric Christopher; CHECK-LABEL: @signed_loop_0_to_n_preincrement_latch_check(
395*cee313d2SEric Christopher; CHECK-NEXT:  entry:
396*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
397*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
398*cee313d2SEric Christopher; CHECK:       loop.preheader:
399*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = add i32 [[LENGTH:%.*]], -1
400*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = icmp sle i32 [[N]], [[TMP0]]
401*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = icmp ult i32 0, [[LENGTH]]
402*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP3:%.*]] = and i1 [[TMP2]], [[TMP1]]
403*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
404*cee313d2SEric Christopher; CHECK:       loop:
405*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
406*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
407*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP3]], i32 9) [ "deopt"() ]
408*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
409*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
410*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
411*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
412*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add i32 [[I]], 1
413*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp slt i32 [[I]], [[N]]
414*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
415*cee313d2SEric Christopher; CHECK:       exit.loopexit:
416*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
417*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
418*cee313d2SEric Christopher; CHECK:       exit:
419*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
420*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
421*cee313d2SEric Christopher;
422*cee313d2SEric Christopherentry:
423*cee313d2SEric Christopher  %tmp5 = icmp sle i32 %n, 0
424*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
425*cee313d2SEric Christopher
426*cee313d2SEric Christopherloop.preheader:
427*cee313d2SEric Christopher  br label %loop
428*cee313d2SEric Christopher
429*cee313d2SEric Christopherloop:
430*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
431*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
432*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %i, %length
433*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
434*cee313d2SEric Christopher
435*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
436*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
437*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
438*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
439*cee313d2SEric Christopher
440*cee313d2SEric Christopher  %i.next = add i32 %i, 1
441*cee313d2SEric Christopher  %continue = icmp slt i32 %i, %n
442*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
443*cee313d2SEric Christopher
444*cee313d2SEric Christopherexit:
445*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
446*cee313d2SEric Christopher  ret i32 %result
447*cee313d2SEric Christopher}
448*cee313d2SEric Christopher
449*cee313d2SEric Christopherdefine i32 @signed_loop_0_to_n_preincrement_latch_check_postincrement_guard_check(i32* %array, i32 %length, i32 %n) {
450*cee313d2SEric Christopher; CHECK-LABEL: @signed_loop_0_to_n_preincrement_latch_check_postincrement_guard_check(
451*cee313d2SEric Christopher; CHECK-NEXT:  entry:
452*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
453*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
454*cee313d2SEric Christopher; CHECK:       loop.preheader:
455*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = add i32 [[LENGTH:%.*]], -2
456*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = icmp sle i32 [[N]], [[TMP0]]
457*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = icmp ult i32 1, [[LENGTH]]
458*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP3:%.*]] = and i1 [[TMP2]], [[TMP1]]
459*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
460*cee313d2SEric Christopher; CHECK:       loop:
461*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
462*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
463*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add i32 [[I]], 1
464*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP3]], i32 9) [ "deopt"() ]
465*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
466*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
467*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
468*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
469*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp slt i32 [[I]], [[N]]
470*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
471*cee313d2SEric Christopher; CHECK:       exit.loopexit:
472*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
473*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
474*cee313d2SEric Christopher; CHECK:       exit:
475*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
476*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
477*cee313d2SEric Christopher;
478*cee313d2SEric Christopherentry:
479*cee313d2SEric Christopher  %tmp5 = icmp sle i32 %n, 0
480*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
481*cee313d2SEric Christopher
482*cee313d2SEric Christopherloop.preheader:
483*cee313d2SEric Christopher  br label %loop
484*cee313d2SEric Christopher
485*cee313d2SEric Christopherloop:
486*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
487*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
488*cee313d2SEric Christopher
489*cee313d2SEric Christopher  %i.next = add i32 %i, 1
490*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %i.next, %length
491*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
492*cee313d2SEric Christopher
493*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
494*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
495*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
496*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
497*cee313d2SEric Christopher
498*cee313d2SEric Christopher  %continue = icmp slt i32 %i, %n
499*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
500*cee313d2SEric Christopher
501*cee313d2SEric Christopherexit:
502*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
503*cee313d2SEric Christopher  ret i32 %result
504*cee313d2SEric Christopher}
505*cee313d2SEric Christopher
506*cee313d2SEric Christopherdefine i32 @signed_loop_0_to_n_sle_latch_offset_ult_check(i32* %array, i32 %length, i32 %n) {
507*cee313d2SEric Christopher; CHECK-LABEL: @signed_loop_0_to_n_sle_latch_offset_ult_check(
508*cee313d2SEric Christopher; CHECK-NEXT:  entry:
509*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
510*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
511*cee313d2SEric Christopher; CHECK:       loop.preheader:
512*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = add i32 [[LENGTH:%.*]], -1
513*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = icmp slt i32 [[N]], [[TMP0]]
514*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = icmp ult i32 1, [[LENGTH]]
515*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP3:%.*]] = and i1 [[TMP2]], [[TMP1]]
516*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
517*cee313d2SEric Christopher; CHECK:       loop:
518*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
519*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
520*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP3]], i32 9) [ "deopt"() ]
521*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
522*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
523*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
524*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
525*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add i32 [[I]], 1
526*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp sle i32 [[I_NEXT]], [[N]]
527*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
528*cee313d2SEric Christopher; CHECK:       exit.loopexit:
529*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
530*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
531*cee313d2SEric Christopher; CHECK:       exit:
532*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
533*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
534*cee313d2SEric Christopher;
535*cee313d2SEric Christopherentry:
536*cee313d2SEric Christopher  %tmp5 = icmp sle i32 %n, 0
537*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
538*cee313d2SEric Christopher
539*cee313d2SEric Christopherloop.preheader:
540*cee313d2SEric Christopher  br label %loop
541*cee313d2SEric Christopher
542*cee313d2SEric Christopherloop:
543*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
544*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
545*cee313d2SEric Christopher  %i.offset = add i32 %i, 1
546*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %i.offset, %length
547*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
548*cee313d2SEric Christopher
549*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
550*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
551*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
552*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
553*cee313d2SEric Christopher
554*cee313d2SEric Christopher  %i.next = add i32 %i, 1
555*cee313d2SEric Christopher  %continue = icmp sle i32 %i.next, %n
556*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
557*cee313d2SEric Christopher
558*cee313d2SEric Christopherexit:
559*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
560*cee313d2SEric Christopher  ret i32 %result
561*cee313d2SEric Christopher}
562*cee313d2SEric Christopher
563*cee313d2SEric Christopherdefine i32 @signed_loop_0_to_n_offset_sle_latch_offset_ult_check(i32* %array, i32 %length, i32 %n) {
564*cee313d2SEric Christopher; CHECK-LABEL: @signed_loop_0_to_n_offset_sle_latch_offset_ult_check(
565*cee313d2SEric Christopher; CHECK-NEXT:  entry:
566*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
567*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
568*cee313d2SEric Christopher; CHECK:       loop.preheader:
569*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = icmp slt i32 [[N]], [[LENGTH:%.*]]
570*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = icmp ult i32 1, [[LENGTH]]
571*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
572*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
573*cee313d2SEric Christopher; CHECK:       loop:
574*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
575*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
576*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP2]], i32 9) [ "deopt"() ]
577*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
578*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
579*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
580*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
581*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add i32 [[I]], 1
582*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT_OFFSET:%.*]] = add i32 [[I_NEXT]], 1
583*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp sle i32 [[I_NEXT_OFFSET]], [[N]]
584*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
585*cee313d2SEric Christopher; CHECK:       exit.loopexit:
586*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
587*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
588*cee313d2SEric Christopher; CHECK:       exit:
589*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
590*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
591*cee313d2SEric Christopher;
592*cee313d2SEric Christopherentry:
593*cee313d2SEric Christopher  %tmp5 = icmp sle i32 %n, 0
594*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
595*cee313d2SEric Christopher
596*cee313d2SEric Christopherloop.preheader:
597*cee313d2SEric Christopher  br label %loop
598*cee313d2SEric Christopher
599*cee313d2SEric Christopherloop:
600*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
601*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
602*cee313d2SEric Christopher  %i.offset = add i32 %i, 1
603*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %i.offset, %length
604*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
605*cee313d2SEric Christopher
606*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
607*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
608*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
609*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
610*cee313d2SEric Christopher
611*cee313d2SEric Christopher  %i.next = add i32 %i, 1
612*cee313d2SEric Christopher  %i.next.offset = add i32 %i.next, 1
613*cee313d2SEric Christopher  %continue = icmp sle i32 %i.next.offset, %n
614*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
615*cee313d2SEric Christopher
616*cee313d2SEric Christopherexit:
617*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
618*cee313d2SEric Christopher  ret i32 %result
619*cee313d2SEric Christopher}
620*cee313d2SEric Christopher
621*cee313d2SEric Christopherdefine i32 @unsupported_latch_pred_loop_0_to_n(i32* %array, i32 %length, i32 %n) {
622*cee313d2SEric Christopher; CHECK-LABEL: @unsupported_latch_pred_loop_0_to_n(
623*cee313d2SEric Christopher; CHECK-NEXT:  entry:
624*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
625*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
626*cee313d2SEric Christopher; CHECK:       loop.preheader:
627*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
628*cee313d2SEric Christopher; CHECK:       loop:
629*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
630*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
631*cee313d2SEric Christopher; CHECK-NEXT:    [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[LENGTH:%.*]]
632*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[WITHIN_BOUNDS]], i32 9) [ "deopt"() ]
633*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
634*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
635*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
636*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
637*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nsw i32 [[I]], 1
638*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp ne i32 [[I_NEXT]], [[N]]
639*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
640*cee313d2SEric Christopher; CHECK:       exit.loopexit:
641*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
642*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
643*cee313d2SEric Christopher; CHECK:       exit:
644*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
645*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
646*cee313d2SEric Christopher;
647*cee313d2SEric Christopherentry:
648*cee313d2SEric Christopher  %tmp5 = icmp sle i32 %n, 0
649*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
650*cee313d2SEric Christopher
651*cee313d2SEric Christopherloop.preheader:
652*cee313d2SEric Christopher  br label %loop
653*cee313d2SEric Christopher
654*cee313d2SEric Christopherloop:
655*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
656*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
657*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %i, %length
658*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
659*cee313d2SEric Christopher
660*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
661*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
662*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
663*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
664*cee313d2SEric Christopher
665*cee313d2SEric Christopher  %i.next = add nsw i32 %i, 1
666*cee313d2SEric Christopher  %continue = icmp ne i32 %i.next, %n
667*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
668*cee313d2SEric Christopher
669*cee313d2SEric Christopherexit:
670*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
671*cee313d2SEric Christopher  ret i32 %result
672*cee313d2SEric Christopher}
673*cee313d2SEric Christopher
674*cee313d2SEric Christopherdefine i32 @signed_loop_0_to_n_unsupported_iv_step(i32* %array, i32 %length, i32 %n) {
675*cee313d2SEric Christopher; CHECK-LABEL: @signed_loop_0_to_n_unsupported_iv_step(
676*cee313d2SEric Christopher; CHECK-NEXT:  entry:
677*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
678*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
679*cee313d2SEric Christopher; CHECK:       loop.preheader:
680*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
681*cee313d2SEric Christopher; CHECK:       loop:
682*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
683*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
684*cee313d2SEric Christopher; CHECK-NEXT:    [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[LENGTH:%.*]]
685*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[WITHIN_BOUNDS]], i32 9) [ "deopt"() ]
686*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
687*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
688*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
689*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
690*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nsw i32 [[I]], 2
691*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp slt i32 [[I_NEXT]], [[N]]
692*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
693*cee313d2SEric Christopher; CHECK:       exit.loopexit:
694*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
695*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
696*cee313d2SEric Christopher; CHECK:       exit:
697*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
698*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
699*cee313d2SEric Christopher;
700*cee313d2SEric Christopherentry:
701*cee313d2SEric Christopher  %tmp5 = icmp sle i32 %n, 0
702*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
703*cee313d2SEric Christopher
704*cee313d2SEric Christopherloop.preheader:
705*cee313d2SEric Christopher  br label %loop
706*cee313d2SEric Christopher
707*cee313d2SEric Christopherloop:
708*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
709*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
710*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %i, %length
711*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
712*cee313d2SEric Christopher
713*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
714*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
715*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
716*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
717*cee313d2SEric Christopher
718*cee313d2SEric Christopher  %i.next = add nsw i32 %i, 2
719*cee313d2SEric Christopher  %continue = icmp slt i32 %i.next, %n
720*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
721*cee313d2SEric Christopher
722*cee313d2SEric Christopherexit:
723*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
724*cee313d2SEric Christopher  ret i32 %result
725*cee313d2SEric Christopher}
726*cee313d2SEric Christopher
727*cee313d2SEric Christopherdefine i32 @signed_loop_0_to_n_equal_iv_range_check(i32* %array, i32 %length, i32 %n) {
728*cee313d2SEric Christopher; CHECK-LABEL: @signed_loop_0_to_n_equal_iv_range_check(
729*cee313d2SEric Christopher; CHECK-NEXT:  entry:
730*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
731*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
732*cee313d2SEric Christopher; CHECK:       loop.preheader:
733*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = icmp sle i32 [[N]], [[LENGTH:%.*]]
734*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH]]
735*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
736*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
737*cee313d2SEric Christopher; CHECK:       loop:
738*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
739*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
740*cee313d2SEric Christopher; CHECK-NEXT:    [[J:%.*]] = phi i32 [ [[J_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
741*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP2]], i32 9) [ "deopt"() ]
742*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
743*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
744*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
745*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
746*cee313d2SEric Christopher; CHECK-NEXT:    [[J_NEXT]] = add nsw i32 [[J]], 1
747*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nsw i32 [[I]], 1
748*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp slt i32 [[I_NEXT]], [[N]]
749*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
750*cee313d2SEric Christopher; CHECK:       exit.loopexit:
751*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
752*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
753*cee313d2SEric Christopher; CHECK:       exit:
754*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
755*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
756*cee313d2SEric Christopher;
757*cee313d2SEric Christopherentry:
758*cee313d2SEric Christopher  %tmp5 = icmp sle i32 %n, 0
759*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
760*cee313d2SEric Christopher
761*cee313d2SEric Christopherloop.preheader:
762*cee313d2SEric Christopher  br label %loop
763*cee313d2SEric Christopher
764*cee313d2SEric Christopherloop:
765*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
766*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
767*cee313d2SEric Christopher  %j = phi i32 [ %j.next, %loop ], [ 0, %loop.preheader ]
768*cee313d2SEric Christopher
769*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %j, %length
770*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
771*cee313d2SEric Christopher
772*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
773*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
774*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
775*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
776*cee313d2SEric Christopher
777*cee313d2SEric Christopher  %j.next = add nsw i32 %j, 1
778*cee313d2SEric Christopher  %i.next = add nsw i32 %i, 1
779*cee313d2SEric Christopher  %continue = icmp slt i32 %i.next, %n
780*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
781*cee313d2SEric Christopher
782*cee313d2SEric Christopherexit:
783*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
784*cee313d2SEric Christopher  ret i32 %result
785*cee313d2SEric Christopher}
786*cee313d2SEric Christopher
787*cee313d2SEric Christopherdefine i32 @signed_loop_start_to_n_offset_iv_range_check(i32* %array, i32 %start.i,
788*cee313d2SEric Christopher; CHECK-LABEL: @signed_loop_start_to_n_offset_iv_range_check(
789*cee313d2SEric Christopher; CHECK-NEXT:  entry:
790*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
791*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
792*cee313d2SEric Christopher; CHECK:       loop.preheader:
793*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = add i32 [[LENGTH:%.*]], [[START_I:%.*]]
794*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = sub i32 [[TMP0]], [[START_J:%.*]]
795*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = icmp sle i32 [[N]], [[TMP1]]
796*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP3:%.*]] = icmp ult i32 [[START_J]], [[LENGTH]]
797*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP4:%.*]] = and i1 [[TMP3]], [[TMP2]]
798*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
799*cee313d2SEric Christopher; CHECK:       loop:
800*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
801*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ [[START_I]], [[LOOP_PREHEADER]] ]
802*cee313d2SEric Christopher; CHECK-NEXT:    [[J:%.*]] = phi i32 [ [[J_NEXT:%.*]], [[LOOP]] ], [ [[START_J]], [[LOOP_PREHEADER]] ]
803*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP4]], i32 9) [ "deopt"() ]
804*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
805*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
806*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
807*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
808*cee313d2SEric Christopher; CHECK-NEXT:    [[J_NEXT]] = add i32 [[J]], 1
809*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add i32 [[I]], 1
810*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp slt i32 [[I_NEXT]], [[N]]
811*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
812*cee313d2SEric Christopher; CHECK:       exit.loopexit:
813*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
814*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
815*cee313d2SEric Christopher; CHECK:       exit:
816*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
817*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
818*cee313d2SEric Christopher;
819*cee313d2SEric Christopher  i32 %start.j, i32 %length,
820*cee313d2SEric Christopher  i32 %n) {
821*cee313d2SEric Christopherentry:
822*cee313d2SEric Christopher  %tmp5 = icmp sle i32 %n, 0
823*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
824*cee313d2SEric Christopher
825*cee313d2SEric Christopherloop.preheader:
826*cee313d2SEric Christopher  br label %loop
827*cee313d2SEric Christopher
828*cee313d2SEric Christopherloop:
829*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
830*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ %start.i, %loop.preheader ]
831*cee313d2SEric Christopher  %j = phi i32 [ %j.next, %loop ], [ %start.j, %loop.preheader ]
832*cee313d2SEric Christopher
833*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %j, %length
834*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
835*cee313d2SEric Christopher
836*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
837*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
838*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
839*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
840*cee313d2SEric Christopher
841*cee313d2SEric Christopher  %j.next = add i32 %j, 1
842*cee313d2SEric Christopher  %i.next = add i32 %i, 1
843*cee313d2SEric Christopher  %continue = icmp slt i32 %i.next, %n
844*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
845*cee313d2SEric Christopher
846*cee313d2SEric Christopherexit:
847*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
848*cee313d2SEric Christopher  ret i32 %result
849*cee313d2SEric Christopher}
850*cee313d2SEric Christopher
851*cee313d2SEric Christopherdefine i32 @signed_loop_0_to_n_different_iv_types(i32* %array, i16 %length, i32 %n) {
852*cee313d2SEric Christopher; CHECK-LABEL: @signed_loop_0_to_n_different_iv_types(
853*cee313d2SEric Christopher; CHECK-NEXT:  entry:
854*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
855*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
856*cee313d2SEric Christopher; CHECK:       loop.preheader:
857*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
858*cee313d2SEric Christopher; CHECK:       loop:
859*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
860*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
861*cee313d2SEric Christopher; CHECK-NEXT:    [[J:%.*]] = phi i16 [ [[J_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
862*cee313d2SEric Christopher; CHECK-NEXT:    [[WITHIN_BOUNDS:%.*]] = icmp ult i16 [[J]], [[LENGTH:%.*]]
863*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[WITHIN_BOUNDS]], i32 9) [ "deopt"() ]
864*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
865*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
866*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
867*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
868*cee313d2SEric Christopher; CHECK-NEXT:    [[J_NEXT]] = add i16 [[J]], 1
869*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add i32 [[I]], 1
870*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp slt i32 [[I_NEXT]], [[N]]
871*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
872*cee313d2SEric Christopher; CHECK:       exit.loopexit:
873*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
874*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
875*cee313d2SEric Christopher; CHECK:       exit:
876*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
877*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
878*cee313d2SEric Christopher;
879*cee313d2SEric Christopherentry:
880*cee313d2SEric Christopher  %tmp5 = icmp sle i32 %n, 0
881*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
882*cee313d2SEric Christopher
883*cee313d2SEric Christopherloop.preheader:
884*cee313d2SEric Christopher  br label %loop
885*cee313d2SEric Christopher
886*cee313d2SEric Christopherloop:
887*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
888*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
889*cee313d2SEric Christopher  %j = phi i16 [ %j.next, %loop ], [ 0, %loop.preheader ]
890*cee313d2SEric Christopher
891*cee313d2SEric Christopher  %within.bounds = icmp ult i16 %j, %length
892*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
893*cee313d2SEric Christopher
894*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
895*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
896*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
897*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
898*cee313d2SEric Christopher
899*cee313d2SEric Christopher  %j.next = add i16 %j, 1
900*cee313d2SEric Christopher  %i.next = add i32 %i, 1
901*cee313d2SEric Christopher  %continue = icmp slt i32 %i.next, %n
902*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
903*cee313d2SEric Christopher
904*cee313d2SEric Christopherexit:
905*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
906*cee313d2SEric Christopher  ret i32 %result
907*cee313d2SEric Christopher}
908*cee313d2SEric Christopher
909*cee313d2SEric Christopherdefine i32 @signed_loop_0_to_n_different_iv_strides(i32* %array, i32 %length, i32 %n) {
910*cee313d2SEric Christopher; CHECK-LABEL: @signed_loop_0_to_n_different_iv_strides(
911*cee313d2SEric Christopher; CHECK-NEXT:  entry:
912*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
913*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
914*cee313d2SEric Christopher; CHECK:       loop.preheader:
915*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
916*cee313d2SEric Christopher; CHECK:       loop:
917*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
918*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
919*cee313d2SEric Christopher; CHECK-NEXT:    [[J:%.*]] = phi i32 [ [[J_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
920*cee313d2SEric Christopher; CHECK-NEXT:    [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[J]], [[LENGTH:%.*]]
921*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[WITHIN_BOUNDS]], i32 9) [ "deopt"() ]
922*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
923*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
924*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
925*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
926*cee313d2SEric Christopher; CHECK-NEXT:    [[J_NEXT]] = add nsw i32 [[J]], 2
927*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nsw i32 [[I]], 1
928*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp slt i32 [[I_NEXT]], [[N]]
929*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
930*cee313d2SEric Christopher; CHECK:       exit.loopexit:
931*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
932*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
933*cee313d2SEric Christopher; CHECK:       exit:
934*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
935*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
936*cee313d2SEric Christopher;
937*cee313d2SEric Christopherentry:
938*cee313d2SEric Christopher  %tmp5 = icmp sle i32 %n, 0
939*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
940*cee313d2SEric Christopher
941*cee313d2SEric Christopherloop.preheader:
942*cee313d2SEric Christopher  br label %loop
943*cee313d2SEric Christopher
944*cee313d2SEric Christopherloop:
945*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
946*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
947*cee313d2SEric Christopher  %j = phi i32 [ %j.next, %loop ], [ 0, %loop.preheader ]
948*cee313d2SEric Christopher
949*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %j, %length
950*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
951*cee313d2SEric Christopher
952*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
953*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
954*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
955*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
956*cee313d2SEric Christopher
957*cee313d2SEric Christopher  %j.next = add nsw i32 %j, 2
958*cee313d2SEric Christopher  %i.next = add nsw i32 %i, 1
959*cee313d2SEric Christopher  %continue = icmp slt i32 %i.next, %n
960*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
961*cee313d2SEric Christopher
962*cee313d2SEric Christopherexit:
963*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
964*cee313d2SEric Christopher  ret i32 %result
965*cee313d2SEric Christopher}
966*cee313d2SEric Christopher
967*cee313d2SEric Christopherdefine i32 @two_range_checks(i32* %array.1, i32 %length.1,
968*cee313d2SEric Christopher; CHECK-LABEL: @two_range_checks(
969*cee313d2SEric Christopher; CHECK-NEXT:  entry:
970*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
971*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
972*cee313d2SEric Christopher; CHECK:       loop.preheader:
973*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = icmp ule i32 [[N]], [[LENGTH_2:%.*]]
974*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH_2]]
975*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
976*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP3:%.*]] = icmp ule i32 [[N]], [[LENGTH_1:%.*]]
977*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP4:%.*]] = icmp ult i32 0, [[LENGTH_1]]
978*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = and i1 [[TMP4]], [[TMP3]]
979*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP6:%.*]] = and i1 [[TMP2]], [[TMP5]]
980*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
981*cee313d2SEric Christopher; CHECK:       loop:
982*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
983*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
984*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP6]], i32 9) [ "deopt"() ]
985*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
986*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_1_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY_1:%.*]], i64 [[I_I64]]
987*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_1_I:%.*]] = load i32, i32* [[ARRAY_1_I_PTR]], align 4
988*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_1:%.*]] = add i32 [[LOOP_ACC]], [[ARRAY_1_I]]
989*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_2_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY_2:%.*]], i64 [[I_I64]]
990*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_2_I:%.*]] = load i32, i32* [[ARRAY_2_I_PTR]], align 4
991*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC_1]], [[ARRAY_2_I]]
992*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nuw i32 [[I]], 1
993*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp ult i32 [[I_NEXT]], [[N]]
994*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
995*cee313d2SEric Christopher; CHECK:       exit.loopexit:
996*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
997*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
998*cee313d2SEric Christopher; CHECK:       exit:
999*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
1000*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
1001*cee313d2SEric Christopher;
1002*cee313d2SEric Christopher  i32* %array.2, i32 %length.2, i32 %n) {
1003*cee313d2SEric Christopherentry:
1004*cee313d2SEric Christopher  %tmp5 = icmp eq i32 %n, 0
1005*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
1006*cee313d2SEric Christopher
1007*cee313d2SEric Christopherloop.preheader:
1008*cee313d2SEric Christopher  br label %loop
1009*cee313d2SEric Christopher
1010*cee313d2SEric Christopherloop:
1011*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
1012*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
1013*cee313d2SEric Christopher  %within.bounds.1 = icmp ult i32 %i, %length.1
1014*cee313d2SEric Christopher  %within.bounds.2 = icmp ult i32 %i, %length.2
1015*cee313d2SEric Christopher  %within.bounds = and i1 %within.bounds.1, %within.bounds.2
1016*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
1017*cee313d2SEric Christopher
1018*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
1019*cee313d2SEric Christopher  %array.1.i.ptr = getelementptr inbounds i32, i32* %array.1, i64 %i.i64
1020*cee313d2SEric Christopher  %array.1.i = load i32, i32* %array.1.i.ptr, align 4
1021*cee313d2SEric Christopher  %loop.acc.1 = add i32 %loop.acc, %array.1.i
1022*cee313d2SEric Christopher
1023*cee313d2SEric Christopher  %array.2.i.ptr = getelementptr inbounds i32, i32* %array.2, i64 %i.i64
1024*cee313d2SEric Christopher  %array.2.i = load i32, i32* %array.2.i.ptr, align 4
1025*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc.1, %array.2.i
1026*cee313d2SEric Christopher
1027*cee313d2SEric Christopher  %i.next = add nuw i32 %i, 1
1028*cee313d2SEric Christopher  %continue = icmp ult i32 %i.next, %n
1029*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
1030*cee313d2SEric Christopher
1031*cee313d2SEric Christopherexit:
1032*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
1033*cee313d2SEric Christopher  ret i32 %result
1034*cee313d2SEric Christopher}
1035*cee313d2SEric Christopher
1036*cee313d2SEric Christopherdefine i32 @three_range_checks(i32* %array.1, i32 %length.1,
1037*cee313d2SEric Christopher; CHECK-LABEL: @three_range_checks(
1038*cee313d2SEric Christopher; CHECK-NEXT:  entry:
1039*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
1040*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
1041*cee313d2SEric Christopher; CHECK:       loop.preheader:
1042*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = icmp ule i32 [[N]], [[LENGTH_3:%.*]]
1043*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH_3]]
1044*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
1045*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP3:%.*]] = icmp ule i32 [[N]], [[LENGTH_2:%.*]]
1046*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP4:%.*]] = icmp ult i32 0, [[LENGTH_2]]
1047*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = and i1 [[TMP4]], [[TMP3]]
1048*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP6:%.*]] = icmp ule i32 [[N]], [[LENGTH_1:%.*]]
1049*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP7:%.*]] = icmp ult i32 0, [[LENGTH_1]]
1050*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP8:%.*]] = and i1 [[TMP7]], [[TMP6]]
1051*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP9:%.*]] = and i1 [[TMP2]], [[TMP5]]
1052*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP10:%.*]] = and i1 [[TMP9]], [[TMP8]]
1053*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
1054*cee313d2SEric Christopher; CHECK:       loop:
1055*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
1056*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
1057*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP10]], i32 9) [ "deopt"() ]
1058*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
1059*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_1_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY_1:%.*]], i64 [[I_I64]]
1060*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_1_I:%.*]] = load i32, i32* [[ARRAY_1_I_PTR]], align 4
1061*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_1:%.*]] = add i32 [[LOOP_ACC]], [[ARRAY_1_I]]
1062*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_2_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY_2:%.*]], i64 [[I_I64]]
1063*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_2_I:%.*]] = load i32, i32* [[ARRAY_2_I_PTR]], align 4
1064*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_2:%.*]] = add i32 [[LOOP_ACC_1]], [[ARRAY_2_I]]
1065*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_3_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY_3:%.*]], i64 [[I_I64]]
1066*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_3_I:%.*]] = load i32, i32* [[ARRAY_3_I_PTR]], align 4
1067*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC_2]], [[ARRAY_3_I]]
1068*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nuw i32 [[I]], 1
1069*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp ult i32 [[I_NEXT]], [[N]]
1070*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
1071*cee313d2SEric Christopher; CHECK:       exit.loopexit:
1072*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
1073*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
1074*cee313d2SEric Christopher; CHECK:       exit:
1075*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
1076*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
1077*cee313d2SEric Christopher;
1078*cee313d2SEric Christopher  i32* %array.2, i32 %length.2,
1079*cee313d2SEric Christopher  i32* %array.3, i32 %length.3, i32 %n) {
1080*cee313d2SEric Christopherentry:
1081*cee313d2SEric Christopher  %tmp5 = icmp eq i32 %n, 0
1082*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
1083*cee313d2SEric Christopher
1084*cee313d2SEric Christopherloop.preheader:
1085*cee313d2SEric Christopher  br label %loop
1086*cee313d2SEric Christopher
1087*cee313d2SEric Christopherloop:
1088*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
1089*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
1090*cee313d2SEric Christopher  %within.bounds.1 = icmp ult i32 %i, %length.1
1091*cee313d2SEric Christopher  %within.bounds.2 = icmp ult i32 %i, %length.2
1092*cee313d2SEric Christopher  %within.bounds.3 = icmp ult i32 %i, %length.3
1093*cee313d2SEric Christopher  %within.bounds.1.and.2 = and i1 %within.bounds.1, %within.bounds.2
1094*cee313d2SEric Christopher  %within.bounds = and i1 %within.bounds.1.and.2, %within.bounds.3
1095*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
1096*cee313d2SEric Christopher
1097*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
1098*cee313d2SEric Christopher  %array.1.i.ptr = getelementptr inbounds i32, i32* %array.1, i64 %i.i64
1099*cee313d2SEric Christopher  %array.1.i = load i32, i32* %array.1.i.ptr, align 4
1100*cee313d2SEric Christopher  %loop.acc.1 = add i32 %loop.acc, %array.1.i
1101*cee313d2SEric Christopher
1102*cee313d2SEric Christopher  %array.2.i.ptr = getelementptr inbounds i32, i32* %array.2, i64 %i.i64
1103*cee313d2SEric Christopher  %array.2.i = load i32, i32* %array.2.i.ptr, align 4
1104*cee313d2SEric Christopher  %loop.acc.2 = add i32 %loop.acc.1, %array.2.i
1105*cee313d2SEric Christopher
1106*cee313d2SEric Christopher  %array.3.i.ptr = getelementptr inbounds i32, i32* %array.3, i64 %i.i64
1107*cee313d2SEric Christopher  %array.3.i = load i32, i32* %array.3.i.ptr, align 4
1108*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc.2, %array.3.i
1109*cee313d2SEric Christopher
1110*cee313d2SEric Christopher  %i.next = add nuw i32 %i, 1
1111*cee313d2SEric Christopher  %continue = icmp ult i32 %i.next, %n
1112*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
1113*cee313d2SEric Christopher
1114*cee313d2SEric Christopherexit:
1115*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
1116*cee313d2SEric Christopher  ret i32 %result
1117*cee313d2SEric Christopher}
1118*cee313d2SEric Christopher
1119*cee313d2SEric Christopherdefine i32 @three_guards(i32* %array.1, i32 %length.1,
1120*cee313d2SEric Christopher; CHECK-LABEL: @three_guards(
1121*cee313d2SEric Christopher; CHECK-NEXT:  entry:
1122*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
1123*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
1124*cee313d2SEric Christopher; CHECK:       loop.preheader:
1125*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = icmp ule i32 [[N]], [[LENGTH_1:%.*]]
1126*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH_1]]
1127*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
1128*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP3:%.*]] = icmp ule i32 [[N]], [[LENGTH_2:%.*]]
1129*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP4:%.*]] = icmp ult i32 0, [[LENGTH_2]]
1130*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = and i1 [[TMP4]], [[TMP3]]
1131*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP6:%.*]] = icmp ule i32 [[N]], [[LENGTH_3:%.*]]
1132*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP7:%.*]] = icmp ult i32 0, [[LENGTH_3]]
1133*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP8:%.*]] = and i1 [[TMP7]], [[TMP6]]
1134*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
1135*cee313d2SEric Christopher; CHECK:       loop:
1136*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
1137*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
1138*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP2]], i32 9) [ "deopt"() ]
1139*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
1140*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_1_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY_1:%.*]], i64 [[I_I64]]
1141*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_1_I:%.*]] = load i32, i32* [[ARRAY_1_I_PTR]], align 4
1142*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_1:%.*]] = add i32 [[LOOP_ACC]], [[ARRAY_1_I]]
1143*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP5]], i32 9) [ "deopt"() ]
1144*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_2_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY_2:%.*]], i64 [[I_I64]]
1145*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_2_I:%.*]] = load i32, i32* [[ARRAY_2_I_PTR]], align 4
1146*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_2:%.*]] = add i32 [[LOOP_ACC_1]], [[ARRAY_2_I]]
1147*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP8]], i32 9) [ "deopt"() ]
1148*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_3_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY_3:%.*]], i64 [[I_I64]]
1149*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_3_I:%.*]] = load i32, i32* [[ARRAY_3_I_PTR]], align 4
1150*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC_2]], [[ARRAY_3_I]]
1151*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nuw i32 [[I]], 1
1152*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp ult i32 [[I_NEXT]], [[N]]
1153*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
1154*cee313d2SEric Christopher; CHECK:       exit.loopexit:
1155*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
1156*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
1157*cee313d2SEric Christopher; CHECK:       exit:
1158*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
1159*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
1160*cee313d2SEric Christopher;
1161*cee313d2SEric Christopher  i32* %array.2, i32 %length.2,
1162*cee313d2SEric Christopher  i32* %array.3, i32 %length.3, i32 %n) {
1163*cee313d2SEric Christopherentry:
1164*cee313d2SEric Christopher  %tmp5 = icmp eq i32 %n, 0
1165*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
1166*cee313d2SEric Christopher
1167*cee313d2SEric Christopherloop.preheader:
1168*cee313d2SEric Christopher  br label %loop
1169*cee313d2SEric Christopher
1170*cee313d2SEric Christopherloop:
1171*cee313d2SEric Christopher
1172*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
1173*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
1174*cee313d2SEric Christopher
1175*cee313d2SEric Christopher  %within.bounds.1 = icmp ult i32 %i, %length.1
1176*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds.1, i32 9) [ "deopt"() ]
1177*cee313d2SEric Christopher
1178*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
1179*cee313d2SEric Christopher  %array.1.i.ptr = getelementptr inbounds i32, i32* %array.1, i64 %i.i64
1180*cee313d2SEric Christopher  %array.1.i = load i32, i32* %array.1.i.ptr, align 4
1181*cee313d2SEric Christopher  %loop.acc.1 = add i32 %loop.acc, %array.1.i
1182*cee313d2SEric Christopher
1183*cee313d2SEric Christopher  %within.bounds.2 = icmp ult i32 %i, %length.2
1184*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds.2, i32 9) [ "deopt"() ]
1185*cee313d2SEric Christopher
1186*cee313d2SEric Christopher  %array.2.i.ptr = getelementptr inbounds i32, i32* %array.2, i64 %i.i64
1187*cee313d2SEric Christopher  %array.2.i = load i32, i32* %array.2.i.ptr, align 4
1188*cee313d2SEric Christopher  %loop.acc.2 = add i32 %loop.acc.1, %array.2.i
1189*cee313d2SEric Christopher
1190*cee313d2SEric Christopher  %within.bounds.3 = icmp ult i32 %i, %length.3
1191*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds.3, i32 9) [ "deopt"() ]
1192*cee313d2SEric Christopher
1193*cee313d2SEric Christopher  %array.3.i.ptr = getelementptr inbounds i32, i32* %array.3, i64 %i.i64
1194*cee313d2SEric Christopher  %array.3.i = load i32, i32* %array.3.i.ptr, align 4
1195*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc.2, %array.3.i
1196*cee313d2SEric Christopher
1197*cee313d2SEric Christopher  %i.next = add nuw i32 %i, 1
1198*cee313d2SEric Christopher  %continue = icmp ult i32 %i.next, %n
1199*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
1200*cee313d2SEric Christopher
1201*cee313d2SEric Christopherexit:
1202*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
1203*cee313d2SEric Christopher  ret i32 %result
1204*cee313d2SEric Christopher}
1205*cee313d2SEric Christopher
1206*cee313d2SEric Christopherdefine i32 @unsigned_loop_0_to_n_unrelated_condition(i32* %array, i32 %length, i32 %n, i32 %x) {
1207*cee313d2SEric Christopher; CHECK-LABEL: @unsigned_loop_0_to_n_unrelated_condition(
1208*cee313d2SEric Christopher; CHECK-NEXT:  entry:
1209*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
1210*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
1211*cee313d2SEric Christopher; CHECK:       loop.preheader:
1212*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = icmp ule i32 [[N]], [[LENGTH:%.*]]
1213*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH]]
1214*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
1215*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
1216*cee313d2SEric Christopher; CHECK:       loop:
1217*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
1218*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
1219*cee313d2SEric Christopher; CHECK-NEXT:    [[UNRELATED_COND:%.*]] = icmp ult i32 [[X:%.*]], [[LENGTH]]
1220*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP3:%.*]] = and i1 [[UNRELATED_COND]], [[TMP2]]
1221*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP3]], i32 9) [ "deopt"() ]
1222*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
1223*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
1224*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
1225*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
1226*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nuw i32 [[I]], 1
1227*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp ult i32 [[I_NEXT]], [[N]]
1228*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
1229*cee313d2SEric Christopher; CHECK:       exit.loopexit:
1230*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
1231*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
1232*cee313d2SEric Christopher; CHECK:       exit:
1233*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
1234*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
1235*cee313d2SEric Christopher;
1236*cee313d2SEric Christopherentry:
1237*cee313d2SEric Christopher  %tmp5 = icmp eq i32 %n, 0
1238*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
1239*cee313d2SEric Christopher
1240*cee313d2SEric Christopherloop.preheader:
1241*cee313d2SEric Christopher  br label %loop
1242*cee313d2SEric Christopher
1243*cee313d2SEric Christopherloop:
1244*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
1245*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
1246*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %i, %length
1247*cee313d2SEric Christopher  %unrelated.cond = icmp ult i32 %x, %length
1248*cee313d2SEric Christopher  %guard.cond = and i1 %within.bounds, %unrelated.cond
1249*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %guard.cond, i32 9) [ "deopt"() ]
1250*cee313d2SEric Christopher
1251*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
1252*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
1253*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
1254*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
1255*cee313d2SEric Christopher
1256*cee313d2SEric Christopher  %i.next = add nuw i32 %i, 1
1257*cee313d2SEric Christopher  %continue = icmp ult i32 %i.next, %n
1258*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
1259*cee313d2SEric Christopher
1260*cee313d2SEric Christopherexit:
1261*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
1262*cee313d2SEric Christopher  ret i32 %result
1263*cee313d2SEric Christopher}
1264*cee313d2SEric Christopher
1265*cee313d2SEric Christopher; Don't change the guard condition if there were no widened subconditions
1266*cee313d2SEric Christopherdefine i32 @test_no_widened_conditions(i32* %array, i32 %length, i32 %n, i32 %x1, i32 %x2, i32 %x3) {
1267*cee313d2SEric Christopher; CHECK-LABEL: @test_no_widened_conditions(
1268*cee313d2SEric Christopher; CHECK-NEXT:  entry:
1269*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
1270*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
1271*cee313d2SEric Christopher; CHECK:       loop.preheader:
1272*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
1273*cee313d2SEric Christopher; CHECK:       loop:
1274*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
1275*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
1276*cee313d2SEric Christopher; CHECK-NEXT:    [[UNRELATED_COND_1:%.*]] = icmp eq i32 [[X1:%.*]], [[I]]
1277*cee313d2SEric Christopher; CHECK-NEXT:    [[UNRELATED_COND_2:%.*]] = icmp eq i32 [[X2:%.*]], [[I]]
1278*cee313d2SEric Christopher; CHECK-NEXT:    [[UNRELATED_COND_3:%.*]] = icmp eq i32 [[X3:%.*]], [[I]]
1279*cee313d2SEric Christopher; CHECK-NEXT:    [[UNRELATED_COND_AND_1:%.*]] = and i1 [[UNRELATED_COND_1]], [[UNRELATED_COND_2]]
1280*cee313d2SEric Christopher; CHECK-NEXT:    [[GUARD_COND:%.*]] = and i1 [[UNRELATED_COND_AND_1]], [[UNRELATED_COND_3]]
1281*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[GUARD_COND]], i32 9) [ "deopt"() ]
1282*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
1283*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
1284*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
1285*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
1286*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nuw i32 [[I]], 1
1287*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp ult i32 [[I_NEXT]], [[N]]
1288*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
1289*cee313d2SEric Christopher; CHECK:       exit.loopexit:
1290*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
1291*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
1292*cee313d2SEric Christopher; CHECK:       exit:
1293*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
1294*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
1295*cee313d2SEric Christopher;
1296*cee313d2SEric Christopherentry:
1297*cee313d2SEric Christopher  %tmp5 = icmp eq i32 %n, 0
1298*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
1299*cee313d2SEric Christopher
1300*cee313d2SEric Christopherloop.preheader:
1301*cee313d2SEric Christopher  br label %loop
1302*cee313d2SEric Christopher
1303*cee313d2SEric Christopherloop:
1304*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
1305*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
1306*cee313d2SEric Christopher  %unrelated.cond.1 = icmp eq i32 %x1, %i
1307*cee313d2SEric Christopher  %unrelated.cond.2 = icmp eq i32 %x2, %i
1308*cee313d2SEric Christopher  %unrelated.cond.3 = icmp eq i32 %x3, %i
1309*cee313d2SEric Christopher  %unrelated.cond.and.1 = and i1 %unrelated.cond.1, %unrelated.cond.2
1310*cee313d2SEric Christopher  %guard.cond = and i1 %unrelated.cond.and.1, %unrelated.cond.3
1311*cee313d2SEric Christopher
1312*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %guard.cond, i32 9) [ "deopt"() ]
1313*cee313d2SEric Christopher
1314*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
1315*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
1316*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
1317*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
1318*cee313d2SEric Christopher
1319*cee313d2SEric Christopher  %i.next = add nuw i32 %i, 1
1320*cee313d2SEric Christopher  %continue = icmp ult i32 %i.next, %n
1321*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
1322*cee313d2SEric Christopher
1323*cee313d2SEric Christopherexit:
1324*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
1325*cee313d2SEric Christopher  ret i32 %result
1326*cee313d2SEric Christopher}
1327*cee313d2SEric Christopher
1328*cee313d2SEric Christopherdefine i32 @signed_loop_start_to_n_loop_variant_bound(i32* %array, i32 %x, i32 %start, i32 %n) {
1329*cee313d2SEric Christopher; CHECK-LABEL: @signed_loop_start_to_n_loop_variant_bound(
1330*cee313d2SEric Christopher; CHECK-NEXT:  entry:
1331*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
1332*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
1333*cee313d2SEric Christopher; CHECK:       loop.preheader:
1334*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
1335*cee313d2SEric Christopher; CHECK:       loop:
1336*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
1337*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ [[START:%.*]], [[LOOP_PREHEADER]] ]
1338*cee313d2SEric Christopher; CHECK-NEXT:    [[BOUND:%.*]] = add i32 [[I]], [[X:%.*]]
1339*cee313d2SEric Christopher; CHECK-NEXT:    [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[BOUND]]
1340*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[WITHIN_BOUNDS]], i32 9) [ "deopt"() ]
1341*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
1342*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
1343*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
1344*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
1345*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nsw i32 [[I]], 1
1346*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp slt i32 [[I_NEXT]], [[N]]
1347*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
1348*cee313d2SEric Christopher; CHECK:       exit.loopexit:
1349*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
1350*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
1351*cee313d2SEric Christopher; CHECK:       exit:
1352*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
1353*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
1354*cee313d2SEric Christopher;
1355*cee313d2SEric Christopherentry:
1356*cee313d2SEric Christopher  %tmp5 = icmp sle i32 %n, 0
1357*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
1358*cee313d2SEric Christopher
1359*cee313d2SEric Christopherloop.preheader:
1360*cee313d2SEric Christopher  br label %loop
1361*cee313d2SEric Christopher
1362*cee313d2SEric Christopherloop:
1363*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
1364*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ %start, %loop.preheader ]
1365*cee313d2SEric Christopher  %bound = add i32 %i, %x
1366*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %i, %bound
1367*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
1368*cee313d2SEric Christopher
1369*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
1370*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
1371*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
1372*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
1373*cee313d2SEric Christopher
1374*cee313d2SEric Christopher  %i.next = add nsw i32 %i, 1
1375*cee313d2SEric Christopher  %continue = icmp slt i32 %i.next, %n
1376*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
1377*cee313d2SEric Christopher
1378*cee313d2SEric Christopherexit:
1379*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
1380*cee313d2SEric Christopher  ret i32 %result
1381*cee313d2SEric Christopher}
1382*cee313d2SEric Christopher
1383*cee313d2SEric Christopherdefine i32 @signed_loop_start_to_n_non_monotonic_predicate(i32* %array, i32 %x, i32 %start, i32 %n) {
1384*cee313d2SEric Christopher; CHECK-LABEL: @signed_loop_start_to_n_non_monotonic_predicate(
1385*cee313d2SEric Christopher; CHECK-NEXT:  entry:
1386*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
1387*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
1388*cee313d2SEric Christopher; CHECK:       loop.preheader:
1389*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
1390*cee313d2SEric Christopher; CHECK:       loop:
1391*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
1392*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ [[START:%.*]], [[LOOP_PREHEADER]] ]
1393*cee313d2SEric Christopher; CHECK-NEXT:    [[GUARD_COND:%.*]] = icmp eq i32 [[I]], [[X:%.*]]
1394*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[GUARD_COND]], i32 9) [ "deopt"() ]
1395*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
1396*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
1397*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
1398*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
1399*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nsw i32 [[I]], 1
1400*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp slt i32 [[I_NEXT]], [[N]]
1401*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
1402*cee313d2SEric Christopher; CHECK:       exit.loopexit:
1403*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
1404*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
1405*cee313d2SEric Christopher; CHECK:       exit:
1406*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
1407*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
1408*cee313d2SEric Christopher;
1409*cee313d2SEric Christopherentry:
1410*cee313d2SEric Christopher  %tmp5 = icmp sle i32 %n, 0
1411*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
1412*cee313d2SEric Christopher
1413*cee313d2SEric Christopherloop.preheader:
1414*cee313d2SEric Christopher  br label %loop
1415*cee313d2SEric Christopher
1416*cee313d2SEric Christopherloop:
1417*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
1418*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ %start, %loop.preheader ]
1419*cee313d2SEric Christopher  %guard.cond = icmp eq i32 %i, %x
1420*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %guard.cond, i32 9) [ "deopt"() ]
1421*cee313d2SEric Christopher
1422*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
1423*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
1424*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
1425*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
1426*cee313d2SEric Christopher
1427*cee313d2SEric Christopher  %i.next = add nsw i32 %i, 1
1428*cee313d2SEric Christopher  %continue = icmp slt i32 %i.next, %n
1429*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
1430*cee313d2SEric Christopher
1431*cee313d2SEric Christopherexit:
1432*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
1433*cee313d2SEric Christopher  ret i32 %result
1434*cee313d2SEric Christopher}
1435*cee313d2SEric Christopher
1436*cee313d2SEric Christopherdefine i32 @unsigned_loop_0_to_n_hoist_length(i32* %array, i16 %length.i16, i32 %n) {
1437*cee313d2SEric Christopher; CHECK-LABEL: @unsigned_loop_0_to_n_hoist_length(
1438*cee313d2SEric Christopher; CHECK-NEXT:  entry:
1439*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
1440*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
1441*cee313d2SEric Christopher; CHECK:       loop.preheader:
1442*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = zext i16 [[LENGTH_I16:%.*]] to i32
1443*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = icmp ule i32 [[N]], [[TMP0]]
1444*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = icmp ult i32 0, [[TMP0]]
1445*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP3:%.*]] = and i1 [[TMP2]], [[TMP1]]
1446*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
1447*cee313d2SEric Christopher; CHECK:       loop:
1448*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
1449*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
1450*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP3]], i32 9) [ "deopt"() ]
1451*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
1452*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
1453*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
1454*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
1455*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nuw i32 [[I]], 1
1456*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp ult i32 [[I_NEXT]], [[N]]
1457*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
1458*cee313d2SEric Christopher; CHECK:       exit.loopexit:
1459*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
1460*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
1461*cee313d2SEric Christopher; CHECK:       exit:
1462*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
1463*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
1464*cee313d2SEric Christopher;
1465*cee313d2SEric Christopherentry:
1466*cee313d2SEric Christopher  %tmp5 = icmp eq i32 %n, 0
1467*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
1468*cee313d2SEric Christopher
1469*cee313d2SEric Christopherloop.preheader:
1470*cee313d2SEric Christopher  br label %loop
1471*cee313d2SEric Christopher
1472*cee313d2SEric Christopherloop:
1473*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
1474*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
1475*cee313d2SEric Christopher  %length = zext i16 %length.i16 to i32
1476*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %i, %length
1477*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
1478*cee313d2SEric Christopher
1479*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
1480*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
1481*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
1482*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
1483*cee313d2SEric Christopher
1484*cee313d2SEric Christopher  %i.next = add nuw i32 %i, 1
1485*cee313d2SEric Christopher  %continue = icmp ult i32 %i.next, %n
1486*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
1487*cee313d2SEric Christopher
1488*cee313d2SEric Christopherexit:
1489*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
1490*cee313d2SEric Christopher  ret i32 %result
1491*cee313d2SEric Christopher}
1492*cee313d2SEric Christopher
1493*cee313d2SEric Christopherdefine i32 @unsigned_loop_0_to_n_cant_hoist_length(i32* %array, i32 %length, i32 %divider, i32 %n) {
1494*cee313d2SEric Christopher; CHECK-LABEL: @unsigned_loop_0_to_n_cant_hoist_length(
1495*cee313d2SEric Christopher; CHECK-NEXT:  entry:
1496*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
1497*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
1498*cee313d2SEric Christopher; CHECK:       loop.preheader:
1499*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
1500*cee313d2SEric Christopher; CHECK:       loop:
1501*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
1502*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
1503*cee313d2SEric Christopher; CHECK-NEXT:    [[LENGTH_UDIV:%.*]] = udiv i32 [[LENGTH:%.*]], [[DIVIDER:%.*]]
1504*cee313d2SEric Christopher; CHECK-NEXT:    [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[LENGTH_UDIV]]
1505*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[WITHIN_BOUNDS]], i32 9) [ "deopt"() ]
1506*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
1507*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
1508*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
1509*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
1510*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nuw i32 [[I]], 1
1511*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp ult i32 [[I_NEXT]], [[N]]
1512*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
1513*cee313d2SEric Christopher; CHECK:       exit.loopexit:
1514*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
1515*cee313d2SEric Christopher; CHECK-NEXT:    br label [[EXIT]]
1516*cee313d2SEric Christopher; CHECK:       exit:
1517*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
1518*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
1519*cee313d2SEric Christopher;
1520*cee313d2SEric Christopherentry:
1521*cee313d2SEric Christopher  %tmp5 = icmp eq i32 %n, 0
1522*cee313d2SEric Christopher  br i1 %tmp5, label %exit, label %loop.preheader
1523*cee313d2SEric Christopher
1524*cee313d2SEric Christopherloop.preheader:
1525*cee313d2SEric Christopher  br label %loop
1526*cee313d2SEric Christopher
1527*cee313d2SEric Christopherloop:
1528*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
1529*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
1530*cee313d2SEric Christopher  %length.udiv = udiv i32 %length, %divider
1531*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %i, %length.udiv
1532*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
1533*cee313d2SEric Christopher
1534*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
1535*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
1536*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
1537*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
1538*cee313d2SEric Christopher
1539*cee313d2SEric Christopher  %i.next = add nuw i32 %i, 1
1540*cee313d2SEric Christopher  %continue = icmp ult i32 %i.next, %n
1541*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
1542*cee313d2SEric Christopher
1543*cee313d2SEric Christopherexit:
1544*cee313d2SEric Christopher  %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %loop ]
1545*cee313d2SEric Christopher  ret i32 %result
1546*cee313d2SEric Christopher}
1547*cee313d2SEric Christopher
1548*cee313d2SEric Christopher
1549*cee313d2SEric Christopher; This is a case where the length information tells us that the guard
1550*cee313d2SEric Christopher; must trigger on some iteration.
1551*cee313d2SEric Christopherdefine i32 @provably_taken(i32* %array, i32* %length.ptr) {
1552*cee313d2SEric Christopher; CHECK-LABEL: @provably_taken(
1553*cee313d2SEric Christopher; CHECK-NEXT:  loop.preheader:
1554*cee313d2SEric Christopher; CHECK-NEXT:    [[LENGTH:%.*]] = load i32, i32* [[LENGTH_PTR:%.*]], !range !1
1555*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = icmp ult i32 0, [[LENGTH]]
1556*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = and i1 [[TMP0]], false
1557*cee313d2SEric Christopher; CHECK-NEXT:    br label [[LOOP:%.*]]
1558*cee313d2SEric Christopher; CHECK:       loop:
1559*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER:%.*]] ]
1560*cee313d2SEric Christopher; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
1561*cee313d2SEric Christopher; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[TMP1]], i32 9) [ "deopt"() ]
1562*cee313d2SEric Christopher; CHECK-NEXT:    [[I_I64:%.*]] = zext i32 [[I]] to i64
1563*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY:%.*]], i64 [[I_I64]]
1564*cee313d2SEric Christopher; CHECK-NEXT:    [[ARRAY_I:%.*]] = load i32, i32* [[ARRAY_I_PTR]], align 4
1565*cee313d2SEric Christopher; CHECK-NEXT:    [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC]], [[ARRAY_I]]
1566*cee313d2SEric Christopher; CHECK-NEXT:    [[I_NEXT]] = add nuw i32 [[I]], 1
1567*cee313d2SEric Christopher; CHECK-NEXT:    [[CONTINUE:%.*]] = icmp slt i32 [[I_NEXT]], 200
1568*cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT:%.*]]
1569*cee313d2SEric Christopher; CHECK:       exit:
1570*cee313d2SEric Christopher; CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[LOOP]] ]
1571*cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[RESULT]]
1572*cee313d2SEric Christopher;
1573*cee313d2SEric Christopherloop.preheader:
1574*cee313d2SEric Christopher  %length = load i32, i32* %length.ptr, !range !{i32 0, i32 50}
1575*cee313d2SEric Christopher  br label %loop
1576*cee313d2SEric Christopher
1577*cee313d2SEric Christopherloop:
1578*cee313d2SEric Christopher  %loop.acc = phi i32 [ %loop.acc.next, %loop ], [ 0, %loop.preheader ]
1579*cee313d2SEric Christopher  %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
1580*cee313d2SEric Christopher  %within.bounds = icmp ult i32 %i, %length
1581*cee313d2SEric Christopher  call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
1582*cee313d2SEric Christopher
1583*cee313d2SEric Christopher  %i.i64 = zext i32 %i to i64
1584*cee313d2SEric Christopher  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
1585*cee313d2SEric Christopher  %array.i = load i32, i32* %array.i.ptr, align 4
1586*cee313d2SEric Christopher  %loop.acc.next = add i32 %loop.acc, %array.i
1587*cee313d2SEric Christopher
1588*cee313d2SEric Christopher  %i.next = add nuw i32 %i, 1
1589*cee313d2SEric Christopher  %continue = icmp slt i32 %i.next, 200
1590*cee313d2SEric Christopher  br i1 %continue, label %loop, label %exit
1591*cee313d2SEric Christopher
1592*cee313d2SEric Christopherexit:
1593*cee313d2SEric Christopher  %result = phi i32 [ %loop.acc.next, %loop ]
1594*cee313d2SEric Christopher  ret i32 %result
1595*cee313d2SEric Christopher}
1596