llvm.org GIT mirror llvm / 5b032bb
[LoopPredication] Support guards expressed as branches by widenable condition This patch adds support of guards expressed as branches by widenable conditions in Loop Predication. Differential Revision: https://reviews.llvm.org/D56081 Reviewed By: reames git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351805 91177308-0d34-0410-b5e6-96231b3b80d8 Max Kazantsev 7 months ago
2 changed file(s) with 1547 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
220220 cl::desc("scale factor for the latch probability. Value should be greater "
221221 "than 1. Lower values are ignored"));
222222
223 static cl::opt PredicateWidenableBranchGuards(
224 "loop-predication-predicate-widenable-branches-to-deopt", cl::Hidden,
225 cl::desc("Whether or not we should predicate guards "
226 "expressed as widenable branches to deoptimize blocks"),
227 cl::init(true));
228
223229 namespace {
224230 class LoopPredication {
225231 /// Represents an induction variable check:
274280 unsigned collectChecks(SmallVectorImpl &Checks, Value *Condition,
275281 SCEVExpander &Expander, IRBuilder<> &Builder);
276282 bool widenGuardConditions(IntrinsicInst *II, SCEVExpander &Expander);
277
283 bool widenWidenableBranchGuardConditions(BranchInst *Guard, SCEVExpander &Expander);
278284 // If the loop always exits through another block in the loop, we should not
279285 // predicate based on the latch check. For example, the latch check can be a
280286 // very coarse grained check and there can be more fine grained exit checks
642648 return true;
643649 }
644650
651 bool LoopPredication::widenWidenableBranchGuardConditions(
652 BranchInst *Guard, SCEVExpander &Expander) {
653 assert(isGuardAsWidenableBranch(Guard) && "Must be!");
654 LLVM_DEBUG(dbgs() << "Processing guard:\n");
655 LLVM_DEBUG(Guard->dump());
656
657 TotalConsidered++;
658 SmallVector Checks;
659 IRBuilder<> Builder(cast(Preheader->getTerminator()));
660 Value *Condition = nullptr, *WidenableCondition = nullptr;
661 BasicBlock *GBB = nullptr, *DBB = nullptr;
662 parseWidenableBranch(Guard, Condition, WidenableCondition, GBB, DBB);
663 unsigned NumWidened = collectChecks(Checks, Condition, Expander, Builder);
664 if (NumWidened == 0)
665 return false;
666
667 TotalWidened += NumWidened;
668
669 // Emit the new guard condition
670 Builder.SetInsertPoint(Guard);
671 Value *LastCheck = nullptr;
672 for (auto *Check : Checks)
673 if (!LastCheck)
674 LastCheck = Check;
675 else
676 LastCheck = Builder.CreateAnd(LastCheck, Check);
677 // Make sure that the check contains widenable condition and therefore can be
678 // further widened.
679 LastCheck = Builder.CreateAnd(LastCheck, WidenableCondition);
680 Guard->setOperand(0, LastCheck);
681 assert(isGuardAsWidenableBranch(Guard) &&
682 "Stopped being a guard after transform?");
683
684 LLVM_DEBUG(dbgs() << "Widened checks = " << NumWidened << "\n");
685 return true;
686 }
687
645688 Optional LoopPredication::parseLoopLatchICmp() {
646689 using namespace PatternMatch;
647690
799842 // There is nothing to do if the module doesn't use guards
800843 auto *GuardDecl =
801844 M->getFunction(Intrinsic::getName(Intrinsic::experimental_guard));
802 if (!GuardDecl || GuardDecl->use_empty())
845 bool HasIntrinsicGuards = GuardDecl && !GuardDecl->use_empty();
846 auto *WCDecl = M->getFunction(
847 Intrinsic::getName(Intrinsic::experimental_widenable_condition));
848 bool HasWidenableConditions =
849 PredicateWidenableBranchGuards && WCDecl && !WCDecl->use_empty();
850 if (!HasIntrinsicGuards && !HasWidenableConditions)
803851 return false;
804852
805853 DL = &M->getDataLayout();
823871 // Collect all the guards into a vector and process later, so as not
824872 // to invalidate the instruction iterator.
825873 SmallVector Guards;
826 for (const auto BB : L->blocks())
874 SmallVector GuardsAsWidenableBranches;
875 for (const auto BB : L->blocks()) {
827876 for (auto &I : *BB)
828877 if (isGuard(&I))
829878 Guards.push_back(cast(&I));
830
831 if (Guards.empty())
879 if (PredicateWidenableBranchGuards &&
880 isGuardAsWidenableBranch(BB->getTerminator()))
881 GuardsAsWidenableBranches.push_back(
882 cast(BB->getTerminator()));
883 }
884
885 if (Guards.empty() && GuardsAsWidenableBranches.empty())
832886 return false;
833887
834888 SCEVExpander Expander(*SE, *DL, "loop-predication");
836890 bool Changed = false;
837891 for (auto *Guard : Guards)
838892 Changed |= widenGuardConditions(Guard, Expander);
893 for (auto *Guard : GuardsAsWidenableBranches)
894 Changed |= widenWidenableBranchGuardConditions(Guard, Expander);
839895
840896 return Changed;
841897 }
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt -S -loop-predication -loop-predication-predicate-widenable-branches-to-deopt=true < %s 2>&1 | FileCheck %s
2 ; RUN: opt -S -passes='require,loop(loop-predication)' -loop-predication-predicate-widenable-branches-to-deopt=true < %s 2>&1 | FileCheck %s
3
4 declare void @llvm.experimental.guard(i1, ...)
5
6 define i32 @unsigned_loop_0_to_n_ult_check(i32* %array, i32 %length, i32 %n) {
7 ; CHECK-LABEL: @unsigned_loop_0_to_n_ult_check(
8 ; CHECK-NEXT: entry:
9 ; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
10 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
11 ; CHECK: loop.preheader:
12 ; CHECK-NEXT: [[TMP0:%.*]] = icmp ule i32 [[N]], [[LENGTH:%.*]]
13 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH]]
14 ; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
15 ; CHECK-NEXT: br label [[LOOP:%.*]]
16 ; CHECK: loop:
17 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
18 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
19 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[LENGTH]]
20 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
21 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
22 ; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[WIDENABLE_COND]]
23 ; CHECK-NEXT: br i1 [[TMP3]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
24 ;
25 entry:
26 %tmp5 = icmp eq i32 %n, 0
27 br i1 %tmp5, label %exit, label %loop.preheader
28
29 loop.preheader: ; preds = %entry
30 br label %loop
31
32 loop: ; preds = %guarded, %loop.preheader
33 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
34 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
35 %within.bounds = icmp ult i32 %i, %length
36 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
37 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
38 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
39
40 deopt: ; preds = %loop
41 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
42 ret i32 %deoptcall
43
44 guarded: ; preds = %loop
45 %i.i64 = zext i32 %i to i64
46 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
47 %array.i = load i32, i32* %array.i.ptr, align 4
48 %loop.acc.next = add i32 %loop.acc, %array.i
49 %i.next = add nuw i32 %i, 1
50 %continue = icmp ult i32 %i.next, %n
51 br i1 %continue, label %loop, label %exit
52
53 exit: ; preds = %guarded, %entry
54 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
55 ret i32 %result
56 }
57
58 define i32 @unsigned_loop_0_to_n_ule_latch_ult_check(i32* %array, i32 %length, i32 %n) {
59 ; CHECK-LABEL: @unsigned_loop_0_to_n_ule_latch_ult_check(
60 ; CHECK-NEXT: entry:
61 ; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
62 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
63 ; CHECK: loop.preheader:
64 ; CHECK-NEXT: [[TMP0:%.*]] = icmp ult i32 [[N]], [[LENGTH:%.*]]
65 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH]]
66 ; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
67 ; CHECK-NEXT: br label [[LOOP:%.*]]
68 ; CHECK: loop:
69 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
70 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
71 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[LENGTH]]
72 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
73 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
74 ; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[WIDENABLE_COND]]
75 ; CHECK-NEXT: br i1 [[TMP3]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
76 ;
77 entry:
78 %tmp5 = icmp eq i32 %n, 0
79 br i1 %tmp5, label %exit, label %loop.preheader
80
81 loop.preheader: ; preds = %entry
82 br label %loop
83
84 loop: ; preds = %guarded, %loop.preheader
85 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
86 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
87 %within.bounds = icmp ult i32 %i, %length
88 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
89 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
90 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
91
92 deopt: ; preds = %loop
93 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
94 ret i32 %deoptcall
95
96 guarded: ; preds = %loop
97 %i.i64 = zext i32 %i to i64
98 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
99 %array.i = load i32, i32* %array.i.ptr, align 4
100 %loop.acc.next = add i32 %loop.acc, %array.i
101 %i.next = add nuw i32 %i, 1
102 %continue = icmp ule i32 %i.next, %n
103 br i1 %continue, label %loop, label %exit
104
105 exit: ; preds = %guarded, %entry
106 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
107 ret i32 %result
108 }
109
110 define i32 @unsigned_loop_0_to_n_ugt_check(i32* %array, i32 %length, i32 %n) {
111 ; CHECK-LABEL: @unsigned_loop_0_to_n_ugt_check(
112 ; CHECK-NEXT: entry:
113 ; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
114 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
115 ; CHECK: loop.preheader:
116 ; CHECK-NEXT: [[TMP0:%.*]] = icmp ule i32 [[N]], [[LENGTH:%.*]]
117 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH]]
118 ; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
119 ; CHECK-NEXT: br label [[LOOP:%.*]]
120 ; CHECK: loop:
121 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
122 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
123 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ugt i32 [[LENGTH]], [[I]]
124 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
125 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
126 ; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[WIDENABLE_COND]]
127 ; CHECK-NEXT: br i1 [[TMP3]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
128 ;
129 entry:
130 %tmp5 = icmp eq i32 %n, 0
131 br i1 %tmp5, label %exit, label %loop.preheader
132
133 loop.preheader: ; preds = %entry
134 br label %loop
135
136 loop: ; preds = %guarded, %loop.preheader
137 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
138 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
139 %within.bounds = icmp ugt i32 %length, %i
140 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
141 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
142 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
143
144 deopt: ; preds = %loop
145 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
146 ret i32 %deoptcall
147
148 guarded: ; preds = %loop
149 %i.i64 = zext i32 %i to i64
150 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
151 %array.i = load i32, i32* %array.i.ptr, align 4
152 %loop.acc.next = add i32 %loop.acc, %array.i
153 %i.next = add nuw i32 %i, 1
154 %continue = icmp ult i32 %i.next, %n
155 br i1 %continue, label %loop, label %exit
156
157 exit: ; preds = %guarded, %entry
158 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
159 ret i32 %result
160 }
161
162 define i32 @signed_loop_0_to_n_ult_check(i32* %array, i32 %length, i32 %n) {
163 ; CHECK-LABEL: @signed_loop_0_to_n_ult_check(
164 ; CHECK-NEXT: entry:
165 ; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
166 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
167 ; CHECK: loop.preheader:
168 ; CHECK-NEXT: [[TMP0:%.*]] = icmp sle i32 [[N]], [[LENGTH:%.*]]
169 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH]]
170 ; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
171 ; CHECK-NEXT: br label [[LOOP:%.*]]
172 ; CHECK: loop:
173 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
174 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
175 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[LENGTH]]
176 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
177 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
178 ; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[WIDENABLE_COND]]
179 ; CHECK-NEXT: br i1 [[TMP3]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
180
181 ;
182 entry:
183 %tmp5 = icmp sle i32 %n, 0
184 br i1 %tmp5, label %exit, label %loop.preheader
185
186 loop.preheader: ; preds = %entry
187 br label %loop
188
189 loop: ; preds = %guarded, %loop.preheader
190 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
191 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
192 %within.bounds = icmp ult i32 %i, %length
193 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
194 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
195 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
196
197 deopt: ; preds = %loop
198 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
199 ret i32 %deoptcall
200
201 guarded: ; preds = %loop
202 %i.i64 = zext i32 %i to i64
203 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
204 %array.i = load i32, i32* %array.i.ptr, align 4
205 %loop.acc.next = add i32 %loop.acc, %array.i
206 %i.next = add nuw i32 %i, 1
207 %continue = icmp slt i32 %i.next, %n
208 br i1 %continue, label %loop, label %exit
209
210 exit: ; preds = %guarded, %entry
211 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
212 ret i32 %result
213 }
214
215 define i32 @signed_loop_0_to_n_ult_check_length_range_known(i32* %array, i32* %length.ptr, i32 %n) {
216 ; CHECK-LABEL: @signed_loop_0_to_n_ult_check_length_range_known(
217 ; CHECK-NEXT: entry:
218 ; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
219 ; CHECK-NEXT: [[LENGTH:%.*]] = load i32, i32* [[LENGTH_PTR:%.*]], !range !1
220 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
221 ; CHECK: loop.preheader:
222 ; CHECK-NEXT: [[TMP0:%.*]] = icmp sle i32 [[N]], [[LENGTH]]
223 ; CHECK-NEXT: [[TMP1:%.*]] = and i1 true, [[TMP0]]
224 ; CHECK-NEXT: br label [[LOOP:%.*]]
225 ; CHECK: loop:
226 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
227 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
228 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[LENGTH]]
229 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
230 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
231 ; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], [[WIDENABLE_COND]]
232 ; CHECK-NEXT: br i1 [[TMP2]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
233 ;
234 entry:
235 %tmp5 = icmp sle i32 %n, 0
236 %length = load i32, i32* %length.ptr, !range !1
237 br i1 %tmp5, label %exit, label %loop.preheader
238
239 loop.preheader: ; preds = %entry
240 br label %loop
241
242 loop: ; preds = %guarded, %loop.preheader
243 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
244 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
245 %within.bounds = icmp ult i32 %i, %length
246 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
247 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
248 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
249
250 deopt: ; preds = %loop
251 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
252 ret i32 %deoptcall
253
254 guarded: ; preds = %loop
255 %i.i64 = zext i32 %i to i64
256 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
257 %array.i = load i32, i32* %array.i.ptr, align 4
258 %loop.acc.next = add i32 %loop.acc, %array.i
259 %i.next = add nuw i32 %i, 1
260 %continue = icmp slt i32 %i.next, %n
261 br i1 %continue, label %loop, label %exit
262
263 exit: ; preds = %guarded, %entry
264 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
265 ret i32 %result
266 }
267
268 define i32 @signed_loop_0_to_n_inverse_latch_predicate(i32* %array, i32 %length, i32 %n) {
269 ; CHECK-LABEL: @signed_loop_0_to_n_inverse_latch_predicate(
270 ; CHECK-NEXT: entry:
271 ; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
272 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
273 ; CHECK: loop.preheader:
274 ; CHECK-NEXT: [[TMP0:%.*]] = icmp slt i32 [[N]], [[LENGTH:%.*]]
275 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH]]
276 ; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
277 ; CHECK-NEXT: br label [[LOOP:%.*]]
278 ; CHECK: loop:
279 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
280 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
281 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[LENGTH]]
282 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
283 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
284 ; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[WIDENABLE_COND]]
285 ; CHECK-NEXT: br i1 [[TMP3]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
286 ;
287 entry:
288 %tmp5 = icmp sle i32 %n, 0
289 br i1 %tmp5, label %exit, label %loop.preheader
290
291 loop.preheader: ; preds = %entry
292 br label %loop
293
294 loop: ; preds = %guarded, %loop.preheader
295 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
296 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
297 %within.bounds = icmp ult i32 %i, %length
298 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
299 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
300 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
301
302 deopt: ; preds = %loop
303 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
304 ret i32 %deoptcall
305
306 guarded: ; preds = %loop
307 %i.i64 = zext i32 %i to i64
308 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
309 %array.i = load i32, i32* %array.i.ptr, align 4
310 %loop.acc.next = add i32 %loop.acc, %array.i
311 %i.next = add nuw i32 %i, 1
312 %continue = icmp sgt i32 %i.next, %n
313 br i1 %continue, label %exit, label %loop
314
315 exit: ; preds = %guarded, %entry
316 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
317 ret i32 %result
318 }
319
320 define i32 @signed_loop_0_to_n_sle_latch_ult_check(i32* %array, i32 %length, i32 %n) {
321 ; CHECK-LABEL: @signed_loop_0_to_n_sle_latch_ult_check(
322 ; CHECK-NEXT: entry:
323 ; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
324 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
325 ; CHECK: loop.preheader:
326 ; CHECK-NEXT: [[TMP0:%.*]] = icmp slt i32 [[N]], [[LENGTH:%.*]]
327 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH]]
328 ; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
329 ; CHECK-NEXT: br label [[LOOP:%.*]]
330 ; CHECK: loop:
331 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
332 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
333 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[LENGTH]]
334 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
335 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
336 ; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[WIDENABLE_COND]]
337 ; CHECK-NEXT: br i1 [[TMP3]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
338 ;
339 entry:
340 %tmp5 = icmp sle i32 %n, 0
341 br i1 %tmp5, label %exit, label %loop.preheader
342
343 loop.preheader: ; preds = %entry
344 br label %loop
345
346 loop: ; preds = %guarded, %loop.preheader
347 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
348 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
349 %within.bounds = icmp ult i32 %i, %length
350 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
351 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
352 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
353
354 deopt: ; preds = %loop
355 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
356 ret i32 %deoptcall
357
358 guarded: ; preds = %loop
359 %i.i64 = zext i32 %i to i64
360 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
361 %array.i = load i32, i32* %array.i.ptr, align 4
362 %loop.acc.next = add i32 %loop.acc, %array.i
363 %i.next = add nuw i32 %i, 1
364 %continue = icmp sle i32 %i.next, %n
365 br i1 %continue, label %loop, label %exit
366
367 exit: ; preds = %guarded, %entry
368 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
369 ret i32 %result
370 }
371
372 define i32 @signed_loop_0_to_n_preincrement_latch_check(i32* %array, i32 %length, i32 %n) {
373 ; CHECK-LABEL: @signed_loop_0_to_n_preincrement_latch_check(
374 ; CHECK-NEXT: entry:
375 ; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
376 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
377 ; CHECK: loop.preheader:
378 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[LENGTH:%.*]], -1
379 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sle i32 [[N]], [[TMP0]]
380 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i32 0, [[LENGTH]]
381 ; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[TMP1]]
382 ; CHECK-NEXT: br label [[LOOP:%.*]]
383 ; CHECK: loop:
384 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
385 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
386 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[LENGTH]]
387 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
388 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
389 ; CHECK-NEXT: [[TMP4:%.*]] = and i1 [[TMP3]], [[WIDENABLE_COND]]
390 ; CHECK-NEXT: br i1 [[TMP4]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
391 ;
392 entry:
393 %tmp5 = icmp sle i32 %n, 0
394 br i1 %tmp5, label %exit, label %loop.preheader
395
396 loop.preheader: ; preds = %entry
397 br label %loop
398
399 loop: ; preds = %guarded, %loop.preheader
400 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
401 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
402 %within.bounds = icmp ult i32 %i, %length
403 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
404 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
405 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
406
407 deopt: ; preds = %loop
408 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
409 ret i32 %deoptcall
410
411 guarded: ; preds = %loop
412 %i.i64 = zext i32 %i to i64
413 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
414 %array.i = load i32, i32* %array.i.ptr, align 4
415 %loop.acc.next = add i32 %loop.acc, %array.i
416 %i.next = add i32 %i, 1
417 %continue = icmp slt i32 %i, %n
418 br i1 %continue, label %loop, label %exit
419
420 exit: ; preds = %guarded, %entry
421 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
422 ret i32 %result
423 }
424
425 define i32 @signed_loop_0_to_n_preincrement_latch_check_postincrement_guard_check(i32* %array, i32 %length, i32 %n) {
426 ; CHECK-LABEL: @signed_loop_0_to_n_preincrement_latch_check_postincrement_guard_check(
427 ; CHECK-NEXT: entry:
428 ; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
429 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
430 ; CHECK: loop.preheader:
431 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[LENGTH:%.*]], -2
432 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sle i32 [[N]], [[TMP0]]
433 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i32 1, [[LENGTH]]
434 ; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[TMP1]]
435 ; CHECK-NEXT: br label [[LOOP:%.*]]
436 ; CHECK: loop:
437 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
438 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
439 ; CHECK-NEXT: [[I_NEXT]] = add i32 [[I]], 1
440 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I_NEXT]], [[LENGTH]]
441 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
442 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
443 ; CHECK-NEXT: [[TMP4:%.*]] = and i1 [[TMP3]], [[WIDENABLE_COND]]
444 ; CHECK-NEXT: br i1 [[TMP4]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
445 ;
446 entry:
447 %tmp5 = icmp sle i32 %n, 0
448 br i1 %tmp5, label %exit, label %loop.preheader
449
450 loop.preheader: ; preds = %entry
451 br label %loop
452
453 loop: ; preds = %guarded, %loop.preheader
454 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
455 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
456 %i.next = add i32 %i, 1
457 %within.bounds = icmp ult i32 %i.next, %length
458 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
459 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
460 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
461
462 deopt: ; preds = %loop
463 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
464 ret i32 %deoptcall
465
466 guarded: ; preds = %loop
467 %i.i64 = zext i32 %i to i64
468 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
469 %array.i = load i32, i32* %array.i.ptr, align 4
470 %loop.acc.next = add i32 %loop.acc, %array.i
471 %continue = icmp slt i32 %i, %n
472 br i1 %continue, label %loop, label %exit
473
474 exit: ; preds = %guarded, %entry
475 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
476 ret i32 %result
477 }
478
479 define i32 @signed_loop_0_to_n_sle_latch_offset_ult_check(i32* %array, i32 %length, i32 %n) {
480 ; CHECK-LABEL: @signed_loop_0_to_n_sle_latch_offset_ult_check(
481 ; CHECK-NEXT: entry:
482 ; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
483 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
484 ; CHECK: loop.preheader:
485 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[LENGTH:%.*]], -1
486 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[N]], [[TMP0]]
487 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i32 1, [[LENGTH]]
488 ; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[TMP1]]
489 ; CHECK-NEXT: br label [[LOOP:%.*]]
490 ; CHECK: loop:
491 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
492 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
493 ; CHECK-NEXT: [[I_OFFSET:%.*]] = add i32 [[I]], 1
494 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I_OFFSET]], [[LENGTH]]
495 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
496 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
497 ; CHECK-NEXT: [[TMP4:%.*]] = and i1 [[TMP3]], [[WIDENABLE_COND]]
498 ; CHECK-NEXT: br i1 [[TMP4]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
499 ;
500 entry:
501 %tmp5 = icmp sle i32 %n, 0
502 br i1 %tmp5, label %exit, label %loop.preheader
503
504 loop.preheader: ; preds = %entry
505 br label %loop
506
507 loop: ; preds = %guarded, %loop.preheader
508 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
509 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
510 %i.offset = add i32 %i, 1
511 %within.bounds = icmp ult i32 %i.offset, %length
512 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
513 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
514 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
515
516 deopt: ; preds = %loop
517 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
518 ret i32 %deoptcall
519
520 guarded: ; preds = %loop
521 %i.i64 = zext i32 %i to i64
522 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
523 %array.i = load i32, i32* %array.i.ptr, align 4
524 %loop.acc.next = add i32 %loop.acc, %array.i
525 %i.next = add i32 %i, 1
526 %continue = icmp sle i32 %i.next, %n
527 br i1 %continue, label %loop, label %exit
528
529 exit: ; preds = %guarded, %entry
530 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
531 ret i32 %result
532 }
533
534 define i32 @signed_loop_0_to_n_offset_sle_latch_offset_ult_check(i32* %array, i32 %length, i32 %n) {
535 ; CHECK-LABEL: @signed_loop_0_to_n_offset_sle_latch_offset_ult_check(
536 ; CHECK-NEXT: entry:
537 ; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
538 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
539 ; CHECK: loop.preheader:
540 ; CHECK-NEXT: [[TMP0:%.*]] = icmp slt i32 [[N]], [[LENGTH:%.*]]
541 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 1, [[LENGTH]]
542 ; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
543 ; CHECK-NEXT: br label [[LOOP:%.*]]
544 ; CHECK: loop:
545 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
546 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
547 ; CHECK-NEXT: [[I_OFFSET:%.*]] = add i32 [[I]], 1
548 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I_OFFSET]], [[LENGTH]]
549 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
550 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
551 ; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[WIDENABLE_COND]]
552 ; CHECK-NEXT: br i1 [[TMP3]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
553 ;
554 entry:
555 %tmp5 = icmp sle i32 %n, 0
556 br i1 %tmp5, label %exit, label %loop.preheader
557
558 loop.preheader: ; preds = %entry
559 br label %loop
560
561 loop: ; preds = %guarded, %loop.preheader
562 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
563 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
564 %i.offset = add i32 %i, 1
565 %within.bounds = icmp ult i32 %i.offset, %length
566 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
567 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
568 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
569
570 deopt: ; preds = %loop
571 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
572 ret i32 %deoptcall
573
574 guarded: ; preds = %loop
575 %i.i64 = zext i32 %i to i64
576 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
577 %array.i = load i32, i32* %array.i.ptr, align 4
578 %loop.acc.next = add i32 %loop.acc, %array.i
579 %i.next = add i32 %i, 1
580 %i.next.offset = add i32 %i.next, 1
581 %continue = icmp sle i32 %i.next.offset, %n
582 br i1 %continue, label %loop, label %exit
583
584 exit: ; preds = %guarded, %entry
585 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
586 ret i32 %result
587 }
588
589 define i32 @unsupported_latch_pred_loop_0_to_n(i32* %array, i32 %length, i32 %n) {
590 ; CHECK-LABEL: @unsupported_latch_pred_loop_0_to_n(
591 ; CHECK-NEXT: entry:
592 ; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
593 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
594 ; CHECK: loop.preheader:
595 ; CHECK-NEXT: br label [[LOOP:%.*]]
596 ; CHECK: loop:
597 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
598 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
599 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[LENGTH:%.*]]
600 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
601 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
602 ; CHECK-NEXT: br i1 [[EXIPLICIT_GUARD_COND]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
603 ;
604 entry:
605 %tmp5 = icmp sle i32 %n, 0
606 br i1 %tmp5, label %exit, label %loop.preheader
607
608 loop.preheader: ; preds = %entry
609 br label %loop
610
611 loop: ; preds = %guarded, %loop.preheader
612 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
613 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
614 %within.bounds = icmp ult i32 %i, %length
615 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
616 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
617 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
618
619 deopt: ; preds = %loop
620 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
621 ret i32 %deoptcall
622
623 guarded: ; preds = %loop
624 %i.i64 = zext i32 %i to i64
625 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
626 %array.i = load i32, i32* %array.i.ptr, align 4
627 %loop.acc.next = add i32 %loop.acc, %array.i
628 %i.next = add nsw i32 %i, 1
629 %continue = icmp ne i32 %i.next, %n
630 br i1 %continue, label %loop, label %exit
631
632 exit: ; preds = %guarded, %entry
633 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
634 ret i32 %result
635 }
636
637 define i32 @signed_loop_0_to_n_unsupported_iv_step(i32* %array, i32 %length, i32 %n) {
638 ; CHECK-LABEL: @signed_loop_0_to_n_unsupported_iv_step(
639 ; CHECK-NEXT: entry:
640 ; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
641 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
642 ; CHECK: loop.preheader:
643 ; CHECK-NEXT: br label [[LOOP:%.*]]
644 ; CHECK: loop:
645 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
646 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
647 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[LENGTH:%.*]]
648 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
649 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
650 ; CHECK-NEXT: br i1 [[EXIPLICIT_GUARD_COND]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
651 ;
652 entry:
653 %tmp5 = icmp sle i32 %n, 0
654 br i1 %tmp5, label %exit, label %loop.preheader
655
656 loop.preheader: ; preds = %entry
657 br label %loop
658
659 loop: ; preds = %guarded, %loop.preheader
660 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
661 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
662 %within.bounds = icmp ult i32 %i, %length
663 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
664 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
665 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
666
667 deopt: ; preds = %loop
668 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
669 ret i32 %deoptcall
670
671 guarded: ; preds = %loop
672 %i.i64 = zext i32 %i to i64
673 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
674 %array.i = load i32, i32* %array.i.ptr, align 4
675 %loop.acc.next = add i32 %loop.acc, %array.i
676 %i.next = add nsw i32 %i, 2
677 %continue = icmp slt i32 %i.next, %n
678 br i1 %continue, label %loop, label %exit
679
680 exit: ; preds = %guarded, %entry
681 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
682 ret i32 %result
683 }
684
685 define i32 @signed_loop_0_to_n_equal_iv_range_check(i32* %array, i32 %length, i32 %n) {
686 ; CHECK-LABEL: @signed_loop_0_to_n_equal_iv_range_check(
687 ; CHECK-NEXT: entry:
688 ; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
689 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
690 ; CHECK: loop.preheader:
691 ; CHECK-NEXT: [[TMP0:%.*]] = icmp sle i32 [[N]], [[LENGTH:%.*]]
692 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH]]
693 ; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
694 ; CHECK-NEXT: br label [[LOOP:%.*]]
695 ; CHECK: loop:
696 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
697 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
698 ; CHECK-NEXT: [[J:%.*]] = phi i32 [ [[J_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
699 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[J]], [[LENGTH]]
700 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
701 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
702 ; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[WIDENABLE_COND]]
703 ; CHECK-NEXT: br i1 [[TMP3]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
704 ;
705 entry:
706 %tmp5 = icmp sle i32 %n, 0
707 br i1 %tmp5, label %exit, label %loop.preheader
708
709 loop.preheader: ; preds = %entry
710 br label %loop
711
712 loop: ; preds = %guarded, %loop.preheader
713 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
714 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
715 %j = phi i32 [ %j.next, %guarded ], [ 0, %loop.preheader ]
716 %within.bounds = icmp ult i32 %j, %length
717 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
718 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
719 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
720
721 deopt: ; preds = %loop
722 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
723 ret i32 %deoptcall
724
725 guarded: ; preds = %loop
726 %i.i64 = zext i32 %i to i64
727 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
728 %array.i = load i32, i32* %array.i.ptr, align 4
729 %loop.acc.next = add i32 %loop.acc, %array.i
730 %j.next = add nsw i32 %j, 1
731 %i.next = add nsw i32 %i, 1
732 %continue = icmp slt i32 %i.next, %n
733 br i1 %continue, label %loop, label %exit
734
735 exit: ; preds = %guarded, %entry
736 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
737 ret i32 %result
738 }
739
740 define i32 @signed_loop_start_to_n_offset_iv_range_check(i32* %array, i32 %start.i, i32 %start.j, i32 %length, i32 %n) {
741 ; CHECK-LABEL: @signed_loop_start_to_n_offset_iv_range_check(
742 ; CHECK-NEXT: entry:
743 ; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
744 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
745 ; CHECK: loop.preheader:
746 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[LENGTH:%.*]], [[START_I:%.*]]
747 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 [[TMP0]], [[START_J:%.*]]
748 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sle i32 [[N]], [[TMP1]]
749 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ult i32 [[START_J]], [[LENGTH]]
750 ; CHECK-NEXT: [[TMP4:%.*]] = and i1 [[TMP3]], [[TMP2]]
751 ; CHECK-NEXT: br label [[LOOP:%.*]]
752 ; CHECK: loop:
753 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
754 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ [[START_I]], [[LOOP_PREHEADER]] ]
755 ; CHECK-NEXT: [[J:%.*]] = phi i32 [ [[J_NEXT:%.*]], [[GUARDED]] ], [ [[START_J]], [[LOOP_PREHEADER]] ]
756 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[J]], [[LENGTH]]
757 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
758 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
759 ; CHECK-NEXT: [[TMP5:%.*]] = and i1 [[TMP4]], [[WIDENABLE_COND]]
760 ; CHECK-NEXT: br i1 [[TMP5]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
761 ;
762 entry:
763 %tmp5 = icmp sle i32 %n, 0
764 br i1 %tmp5, label %exit, label %loop.preheader
765
766 loop.preheader: ; preds = %entry
767 br label %loop
768
769 loop: ; preds = %guarded, %loop.preheader
770 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
771 %i = phi i32 [ %i.next, %guarded ], [ %start.i, %loop.preheader ]
772 %j = phi i32 [ %j.next, %guarded ], [ %start.j, %loop.preheader ]
773 %within.bounds = icmp ult i32 %j, %length
774 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
775 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
776 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
777
778 deopt: ; preds = %loop
779 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
780 ret i32 %deoptcall
781
782 guarded: ; preds = %loop
783 %i.i64 = zext i32 %i to i64
784 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
785 %array.i = load i32, i32* %array.i.ptr, align 4
786 %loop.acc.next = add i32 %loop.acc, %array.i
787 %j.next = add i32 %j, 1
788 %i.next = add i32 %i, 1
789 %continue = icmp slt i32 %i.next, %n
790 br i1 %continue, label %loop, label %exit
791
792 exit: ; preds = %guarded, %entry
793 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
794 ret i32 %result
795 }
796
797 define i32 @signed_loop_0_to_n_different_iv_types(i32* %array, i16 %length, i32 %n) {
798 ; CHECK-LABEL: @signed_loop_0_to_n_different_iv_types(
799 ; CHECK-NEXT: entry:
800 ; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
801 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
802 ; CHECK: loop.preheader:
803 ; CHECK-NEXT: br label [[LOOP:%.*]]
804 ; CHECK: loop:
805 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
806 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
807 ; CHECK-NEXT: [[J:%.*]] = phi i16 [ [[J_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
808 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i16 [[J]], [[LENGTH:%.*]]
809 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
810 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
811 ; CHECK-NEXT: br i1 [[EXIPLICIT_GUARD_COND]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
812 ;
813 entry:
814 %tmp5 = icmp sle i32 %n, 0
815 br i1 %tmp5, label %exit, label %loop.preheader
816
817 loop.preheader: ; preds = %entry
818 br label %loop
819
820 loop: ; preds = %guarded, %loop.preheader
821 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
822 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
823 %j = phi i16 [ %j.next, %guarded ], [ 0, %loop.preheader ]
824 %within.bounds = icmp ult i16 %j, %length
825 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
826 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
827 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
828
829 deopt: ; preds = %loop
830 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
831 ret i32 %deoptcall
832
833 guarded: ; preds = %loop
834 %i.i64 = zext i32 %i to i64
835 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
836 %array.i = load i32, i32* %array.i.ptr, align 4
837 %loop.acc.next = add i32 %loop.acc, %array.i
838 %j.next = add i16 %j, 1
839 %i.next = add i32 %i, 1
840 %continue = icmp slt i32 %i.next, %n
841 br i1 %continue, label %loop, label %exit
842
843 exit: ; preds = %guarded, %entry
844 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
845 ret i32 %result
846 }
847
848 define i32 @signed_loop_0_to_n_different_iv_strides(i32* %array, i32 %length, i32 %n) {
849 ; CHECK-LABEL: @signed_loop_0_to_n_different_iv_strides(
850 ; CHECK-NEXT: entry:
851 ; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
852 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
853 ; CHECK: loop.preheader:
854 ; CHECK-NEXT: br label [[LOOP:%.*]]
855 ; CHECK: loop:
856 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
857 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
858 ; CHECK-NEXT: [[J:%.*]] = phi i32 [ [[J_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
859 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[J]], [[LENGTH:%.*]]
860 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
861 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
862 ; CHECK-NEXT: br i1 [[EXIPLICIT_GUARD_COND]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
863 ;
864 entry:
865 %tmp5 = icmp sle i32 %n, 0
866 br i1 %tmp5, label %exit, label %loop.preheader
867
868 loop.preheader: ; preds = %entry
869 br label %loop
870
871 loop: ; preds = %guarded, %loop.preheader
872 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
873 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
874 %j = phi i32 [ %j.next, %guarded ], [ 0, %loop.preheader ]
875 %within.bounds = icmp ult i32 %j, %length
876 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
877 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
878 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
879
880 deopt: ; preds = %loop
881 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
882 ret i32 %deoptcall
883
884 guarded: ; preds = %loop
885 %i.i64 = zext i32 %i to i64
886 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
887 %array.i = load i32, i32* %array.i.ptr, align 4
888 %loop.acc.next = add i32 %loop.acc, %array.i
889 %j.next = add nsw i32 %j, 2
890 %i.next = add nsw i32 %i, 1
891 %continue = icmp slt i32 %i.next, %n
892 br i1 %continue, label %loop, label %exit
893
894 exit: ; preds = %guarded, %entry
895 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
896 ret i32 %result
897 }
898
899 define i32 @two_range_checks(i32* %array.1, i32 %length.1, i32* %array.2, i32 %length.2, i32 %n) {
900 ; CHECK-LABEL: @two_range_checks(
901 ; CHECK-NEXT: entry:
902 ; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
903 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
904 ; CHECK: loop.preheader:
905 ; CHECK-NEXT: [[TMP0:%.*]] = icmp ule i32 [[N]], [[LENGTH_2:%.*]]
906 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH_2]]
907 ; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
908 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ule i32 [[N]], [[LENGTH_1:%.*]]
909 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ult i32 0, [[LENGTH_1]]
910 ; CHECK-NEXT: [[TMP5:%.*]] = and i1 [[TMP4]], [[TMP3]]
911 ; CHECK-NEXT: br label [[LOOP:%.*]]
912 ; CHECK: loop:
913 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
914 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
915 ; CHECK-NEXT: [[WITHIN_BOUNDS_1:%.*]] = icmp ult i32 [[I]], [[LENGTH_1]]
916 ; CHECK-NEXT: [[WITHIN_BOUNDS_2:%.*]] = icmp ult i32 [[I]], [[LENGTH_2]]
917 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = and i1 [[WITHIN_BOUNDS_1]], [[WITHIN_BOUNDS_2]]
918 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
919 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
920 ; CHECK-NEXT: [[TMP6:%.*]] = and i1 [[TMP2]], [[TMP5]]
921 ; CHECK-NEXT: [[TMP7:%.*]] = and i1 [[TMP6]], [[WIDENABLE_COND]]
922 ; CHECK-NEXT: br i1 [[TMP7]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
923 ;
924 entry:
925 %tmp5 = icmp eq i32 %n, 0
926 br i1 %tmp5, label %exit, label %loop.preheader
927
928 loop.preheader: ; preds = %entry
929 br label %loop
930
931 loop: ; preds = %guarded, %loop.preheader
932 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
933 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
934 %within.bounds.1 = icmp ult i32 %i, %length.1
935 %within.bounds.2 = icmp ult i32 %i, %length.2
936 %within.bounds = and i1 %within.bounds.1, %within.bounds.2
937 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
938 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
939 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
940
941 deopt: ; preds = %loop
942 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
943 ret i32 %deoptcall
944
945 guarded: ; preds = %loop
946 %i.i64 = zext i32 %i to i64
947 %array.1.i.ptr = getelementptr inbounds i32, i32* %array.1, i64 %i.i64
948 %array.1.i = load i32, i32* %array.1.i.ptr, align 4
949 %loop.acc.1 = add i32 %loop.acc, %array.1.i
950 %array.2.i.ptr = getelementptr inbounds i32, i32* %array.2, i64 %i.i64
951 %array.2.i = load i32, i32* %array.2.i.ptr, align 4
952 %loop.acc.next = add i32 %loop.acc.1, %array.2.i
953 %i.next = add nuw i32 %i, 1
954 %continue = icmp ult i32 %i.next, %n
955 br i1 %continue, label %loop, label %exit
956
957 exit: ; preds = %guarded, %entry
958 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
959 ret i32 %result
960 }
961
962 define i32 @three_range_checks(i32* %array.1, i32 %length.1, i32* %array.2, i32 %length.2, i32* %array.3, i32 %length.3, i32 %n) {
963 ; CHECK-LABEL: @three_range_checks(
964 ; CHECK-NEXT: entry:
965 ; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
966 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
967 ; CHECK: loop.preheader:
968 ; CHECK-NEXT: [[TMP0:%.*]] = icmp ule i32 [[N]], [[LENGTH_3:%.*]]
969 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH_3]]
970 ; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
971 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ule i32 [[N]], [[LENGTH_2:%.*]]
972 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ult i32 0, [[LENGTH_2]]
973 ; CHECK-NEXT: [[TMP5:%.*]] = and i1 [[TMP4]], [[TMP3]]
974 ; CHECK-NEXT: [[TMP6:%.*]] = icmp ule i32 [[N]], [[LENGTH_1:%.*]]
975 ; CHECK-NEXT: [[TMP7:%.*]] = icmp ult i32 0, [[LENGTH_1]]
976 ; CHECK-NEXT: [[TMP8:%.*]] = and i1 [[TMP7]], [[TMP6]]
977 ; CHECK-NEXT: br label [[LOOP:%.*]]
978 ; CHECK: loop:
979 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
980 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
981 ; CHECK-NEXT: [[WITHIN_BOUNDS_1:%.*]] = icmp ult i32 [[I]], [[LENGTH_1]]
982 ; CHECK-NEXT: [[WITHIN_BOUNDS_2:%.*]] = icmp ult i32 [[I]], [[LENGTH_2]]
983 ; CHECK-NEXT: [[WITHIN_BOUNDS_3:%.*]] = icmp ult i32 [[I]], [[LENGTH_3]]
984 ; CHECK-NEXT: [[WITHIN_BOUNDS_1_AND_2:%.*]] = and i1 [[WITHIN_BOUNDS_1]], [[WITHIN_BOUNDS_2]]
985 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = and i1 [[WITHIN_BOUNDS_1_AND_2]], [[WITHIN_BOUNDS_3]]
986 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
987 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
988 ; CHECK-NEXT: [[TMP9:%.*]] = and i1 [[TMP2]], [[TMP5]]
989 ; CHECK-NEXT: [[TMP10:%.*]] = and i1 [[TMP9]], [[TMP8]]
990 ; CHECK-NEXT: [[TMP11:%.*]] = and i1 [[TMP10]], [[WIDENABLE_COND]]
991 ; CHECK-NEXT: br i1 [[TMP11]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
992 ;
993 entry:
994 %tmp5 = icmp eq i32 %n, 0
995 br i1 %tmp5, label %exit, label %loop.preheader
996
997 loop.preheader: ; preds = %entry
998 br label %loop
999
1000 loop: ; preds = %guarded, %loop.preheader
1001 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
1002 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
1003 %within.bounds.1 = icmp ult i32 %i, %length.1
1004 %within.bounds.2 = icmp ult i32 %i, %length.2
1005 %within.bounds.3 = icmp ult i32 %i, %length.3
1006 %within.bounds.1.and.2 = and i1 %within.bounds.1, %within.bounds.2
1007 %within.bounds = and i1 %within.bounds.1.and.2, %within.bounds.3
1008 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
1009 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
1010 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
1011
1012 deopt: ; preds = %loop
1013 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
1014 ret i32 %deoptcall
1015
1016 guarded: ; preds = %loop
1017 %i.i64 = zext i32 %i to i64
1018 %array.1.i.ptr = getelementptr inbounds i32, i32* %array.1, i64 %i.i64
1019 %array.1.i = load i32, i32* %array.1.i.ptr, align 4
1020 %loop.acc.1 = add i32 %loop.acc, %array.1.i
1021 %array.2.i.ptr = getelementptr inbounds i32, i32* %array.2, i64 %i.i64
1022 %array.2.i = load i32, i32* %array.2.i.ptr, align 4
1023 %loop.acc.2 = add i32 %loop.acc.1, %array.2.i
1024 %array.3.i.ptr = getelementptr inbounds i32, i32* %array.3, i64 %i.i64
1025 %array.3.i = load i32, i32* %array.3.i.ptr, align 4
1026 %loop.acc.next = add i32 %loop.acc.2, %array.3.i
1027 %i.next = add nuw i32 %i, 1
1028 %continue = icmp ult i32 %i.next, %n
1029 br i1 %continue, label %loop, label %exit
1030
1031 exit: ; preds = %guarded, %entry
1032 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
1033 ret i32 %result
1034 }
1035
1036 define i32 @three_guards(i32* %array.1, i32 %length.1, i32* %array.2, i32 %length.2, i32* %array.3, i32 %length.3, i32 %n) {
1037 ; CHECK-LABEL: @three_guards(
1038 ; CHECK-NEXT: entry:
1039 ; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
1040 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
1041 ; CHECK: loop.preheader:
1042 ; CHECK-NEXT: [[TMP0:%.*]] = icmp ule i32 [[N]], [[LENGTH_1:%.*]]
1043 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH_1]]
1044 ; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
1045 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ule i32 [[N]], [[LENGTH_2:%.*]]
1046 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ult i32 0, [[LENGTH_2]]
1047 ; CHECK-NEXT: [[TMP5:%.*]] = and i1 [[TMP4]], [[TMP3]]
1048 ; CHECK-NEXT: [[TMP6:%.*]] = icmp ule i32 [[N]], [[LENGTH_3:%.*]]
1049 ; CHECK-NEXT: [[TMP7:%.*]] = icmp ult i32 0, [[LENGTH_3]]
1050 ; CHECK-NEXT: [[TMP8:%.*]] = and i1 [[TMP7]], [[TMP6]]
1051 ; CHECK-NEXT: br label [[LOOP:%.*]]
1052 ; CHECK: loop:
1053 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED6:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
1054 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED6]] ], [ 0, [[LOOP_PREHEADER]] ]
1055 ; CHECK-NEXT: [[WITHIN_BOUNDS_1:%.*]] = icmp ult i32 [[I]], [[LENGTH_1]]
1056 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
1057 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS_1]], [[WIDENABLE_COND]]
1058 ; CHECK-NEXT: [[TMP9:%.*]] = and i1 [[TMP2]], [[WIDENABLE_COND]]
1059 ; CHECK-NEXT: br i1 [[TMP9]], label [[GUARDED:%.*]], label [[DEOPT:%.*]], !prof !0
1060 ; CHECK: deopt:
1061 ; CHECK-NEXT: [[DEOPTCALL:%.*]] = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
1062 ; CHECK-NEXT: ret i32 [[DEOPTCALL]]
1063 ; CHECK: guarded:
1064 ; CHECK-NEXT: [[I_I64:%.*]] = zext i32 [[I]] to i64
1065 ; CHECK-NEXT: [[ARRAY_1_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY_1:%.*]], i64 [[I_I64]]
1066 ; CHECK-NEXT: [[ARRAY_1_I:%.*]] = load i32, i32* [[ARRAY_1_I_PTR]], align 4
1067 ; CHECK-NEXT: [[LOOP_ACC_1:%.*]] = add i32 [[LOOP_ACC]], [[ARRAY_1_I]]
1068 ; CHECK-NEXT: [[WITHIN_BOUNDS_2:%.*]] = icmp ult i32 [[I]], [[LENGTH_2]]
1069 ; CHECK-NEXT: [[WIDENABLE_COND4:%.*]] = call i1 @llvm.experimental.widenable.condition()
1070 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND5:%.*]] = and i1 [[WITHIN_BOUNDS_2]], [[WIDENABLE_COND4]]
1071 ; CHECK-NEXT: [[TMP10:%.*]] = and i1 [[TMP5]], [[WIDENABLE_COND4]]
1072 ; CHECK-NEXT: br i1 [[TMP10]], label [[GUARDED1:%.*]], label [[DEOPT2:%.*]], !prof !0
1073 ; CHECK: deopt2:
1074 ; CHECK-NEXT: [[DEOPTCALL3:%.*]] = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
1075 ; CHECK-NEXT: ret i32 [[DEOPTCALL3]]
1076 ; CHECK: guarded1:
1077 ; CHECK-NEXT: [[ARRAY_2_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY_2:%.*]], i64 [[I_I64]]
1078 ; CHECK-NEXT: [[ARRAY_2_I:%.*]] = load i32, i32* [[ARRAY_2_I_PTR]], align 4
1079 ; CHECK-NEXT: [[LOOP_ACC_2:%.*]] = add i32 [[LOOP_ACC_1]], [[ARRAY_2_I]]
1080 ; CHECK-NEXT: [[WITHIN_BOUNDS_3:%.*]] = icmp ult i32 [[I]], [[LENGTH_3]]
1081 ; CHECK-NEXT: [[WIDENABLE_COND9:%.*]] = call i1 @llvm.experimental.widenable.condition()
1082 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND10:%.*]] = and i1 [[WITHIN_BOUNDS_3]], [[WIDENABLE_COND9]]
1083 ; CHECK-NEXT: [[TMP11:%.*]] = and i1 [[TMP8]], [[WIDENABLE_COND9]]
1084 ; CHECK-NEXT: br i1 [[TMP11]], label [[GUARDED6]], label [[DEOPT7:%.*]], !prof !0
1085 ; CHECK: deopt7:
1086 ; CHECK-NEXT: [[DEOPTCALL8:%.*]] = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
1087 ; CHECK-NEXT: ret i32 [[DEOPTCALL8]]
1088 ; CHECK: guarded6:
1089 ; CHECK-NEXT: [[ARRAY_3_I_PTR:%.*]] = getelementptr inbounds i32, i32* [[ARRAY_3:%.*]], i64 [[I_I64]]
1090 ; CHECK-NEXT: [[ARRAY_3_I:%.*]] = load i32, i32* [[ARRAY_3_I_PTR]], align 4
1091 ; CHECK-NEXT: [[LOOP_ACC_NEXT]] = add i32 [[LOOP_ACC_2]], [[ARRAY_3_I]]
1092 ; CHECK-NEXT: [[I_NEXT]] = add nuw i32 [[I]], 1
1093 ; CHECK-NEXT: [[CONTINUE:%.*]] = icmp ult i32 [[I_NEXT]], [[N]]
1094 ; CHECK-NEXT: br i1 [[CONTINUE]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
1095 ; CHECK: exit.loopexit:
1096 ; CHECK-NEXT: [[LOOP_ACC_NEXT_LCSSA:%.*]] = phi i32 [ [[LOOP_ACC_NEXT]], [[GUARDED6]] ]
1097 ; CHECK-NEXT: br label [[EXIT]]
1098 ; CHECK: exit:
1099 ; CHECK-NEXT: [[RESULT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LOOP_ACC_NEXT_LCSSA]], [[EXIT_LOOPEXIT]] ]
1100 ; CHECK-NEXT: ret i32 [[RESULT]]
1101 ;
1102 entry:
1103 %tmp5 = icmp eq i32 %n, 0
1104 br i1 %tmp5, label %exit, label %loop.preheader
1105
1106 loop.preheader: ; preds = %entry
1107 br label %loop
1108
1109 loop: ; preds = %guarded6, %loop.preheader
1110 %loop.acc = phi i32 [ %loop.acc.next, %guarded6 ], [ 0, %loop.preheader ]
1111 %i = phi i32 [ %i.next, %guarded6 ], [ 0, %loop.preheader ]
1112 %within.bounds.1 = icmp ult i32 %i, %length.1
1113 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
1114 %exiplicit_guard_cond = and i1 %within.bounds.1, %widenable_cond
1115 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
1116
1117 deopt: ; preds = %loop
1118 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
1119 ret i32 %deoptcall
1120
1121 guarded: ; preds = %loop
1122 %i.i64 = zext i32 %i to i64
1123 %array.1.i.ptr = getelementptr inbounds i32, i32* %array.1, i64 %i.i64
1124 %array.1.i = load i32, i32* %array.1.i.ptr, align 4
1125 %loop.acc.1 = add i32 %loop.acc, %array.1.i
1126 %within.bounds.2 = icmp ult i32 %i, %length.2
1127 %widenable_cond4 = call i1 @llvm.experimental.widenable.condition()
1128 %exiplicit_guard_cond5 = and i1 %within.bounds.2, %widenable_cond4
1129 br i1 %exiplicit_guard_cond5, label %guarded1, label %deopt2, !prof !0
1130
1131 deopt2: ; preds = %guarded
1132 %deoptcall3 = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
1133 ret i32 %deoptcall3
1134
1135 guarded1: ; preds = %guarded
1136 %array.2.i.ptr = getelementptr inbounds i32, i32* %array.2, i64 %i.i64
1137 %array.2.i = load i32, i32* %array.2.i.ptr, align 4
1138 %loop.acc.2 = add i32 %loop.acc.1, %array.2.i
1139 %within.bounds.3 = icmp ult i32 %i, %length.3
1140 %widenable_cond9 = call i1 @llvm.experimental.widenable.condition()
1141 %exiplicit_guard_cond10 = and i1 %within.bounds.3, %widenable_cond9
1142 br i1 %exiplicit_guard_cond10, label %guarded6, label %deopt7, !prof !0
1143
1144 deopt7: ; preds = %guarded1
1145 %deoptcall8 = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
1146 ret i32 %deoptcall8
1147
1148 guarded6: ; preds = %guarded1
1149 %array.3.i.ptr = getelementptr inbounds i32, i32* %array.3, i64 %i.i64
1150 %array.3.i = load i32, i32* %array.3.i.ptr, align 4
1151 %loop.acc.next = add i32 %loop.acc.2, %array.3.i
1152 %i.next = add nuw i32 %i, 1
1153 %continue = icmp ult i32 %i.next, %n
1154 br i1 %continue, label %loop, label %exit
1155
1156 exit: ; preds = %guarded6, %entry
1157 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded6 ]
1158 ret i32 %result
1159 }
1160
1161 define i32 @unsigned_loop_0_to_n_unrelated_condition(i32* %array, i32 %length, i32 %n, i32 %x) {
1162 ; CHECK-LABEL: @unsigned_loop_0_to_n_unrelated_condition(
1163 ; CHECK-NEXT: entry:
1164 ; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
1165 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
1166 ; CHECK: loop.preheader:
1167 ; CHECK-NEXT: [[TMP0:%.*]] = icmp ule i32 [[N]], [[LENGTH:%.*]]
1168 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 0, [[LENGTH]]
1169 ; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], [[TMP0]]
1170 ; CHECK-NEXT: br label [[LOOP:%.*]]
1171 ; CHECK: loop:
1172 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
1173 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
1174 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[LENGTH]]
1175 ; CHECK-NEXT: [[UNRELATED_COND:%.*]] = icmp ult i32 [[X:%.*]], [[LENGTH]]
1176 ; CHECK-NEXT: [[GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[UNRELATED_COND]]
1177 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
1178 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[GUARD_COND]], [[WIDENABLE_COND]]
1179 ; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[UNRELATED_COND]], [[TMP2]]
1180 ; CHECK-NEXT: [[TMP4:%.*]] = and i1 [[TMP3]], [[WIDENABLE_COND]]
1181 ; CHECK-NEXT: br i1 [[TMP4]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
1182 ;
1183 entry:
1184 %tmp5 = icmp eq i32 %n, 0
1185 br i1 %tmp5, label %exit, label %loop.preheader
1186
1187 loop.preheader: ; preds = %entry
1188 br label %loop
1189
1190 loop: ; preds = %guarded, %loop.preheader
1191 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
1192 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
1193 %within.bounds = icmp ult i32 %i, %length
1194 %unrelated.cond = icmp ult i32 %x, %length
1195 %guard.cond = and i1 %within.bounds, %unrelated.cond
1196 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
1197 %exiplicit_guard_cond = and i1 %guard.cond, %widenable_cond
1198 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
1199
1200 deopt: ; preds = %loop
1201 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
1202 ret i32 %deoptcall
1203
1204 guarded: ; preds = %loop
1205 %i.i64 = zext i32 %i to i64
1206 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
1207 %array.i = load i32, i32* %array.i.ptr, align 4
1208 %loop.acc.next = add i32 %loop.acc, %array.i
1209 %i.next = add nuw i32 %i, 1
1210 %continue = icmp ult i32 %i.next, %n
1211 br i1 %continue, label %loop, label %exit
1212
1213 exit: ; preds = %guarded, %entry
1214 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
1215 ret i32 %result
1216 }
1217
1218 define i32 @test_no_widened_conditions(i32* %array, i32 %length, i32 %n, i32 %x1, i32 %x2, i32 %x3) {
1219 ; CHECK-LABEL: @test_no_widened_conditions(
1220 ; CHECK-NEXT: entry:
1221 ; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
1222 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
1223 ; CHECK: loop.preheader:
1224 ; CHECK-NEXT: br label [[LOOP:%.*]]
1225 ; CHECK: loop:
1226 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
1227 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
1228 ; CHECK-NEXT: [[UNRELATED_COND_1:%.*]] = icmp eq i32 [[X1:%.*]], [[I]]
1229 ; CHECK-NEXT: [[UNRELATED_COND_2:%.*]] = icmp eq i32 [[X2:%.*]], [[I]]
1230 ; CHECK-NEXT: [[UNRELATED_COND_3:%.*]] = icmp eq i32 [[X3:%.*]], [[I]]
1231 ; CHECK-NEXT: [[UNRELATED_COND_AND_1:%.*]] = and i1 [[UNRELATED_COND_1]], [[UNRELATED_COND_2]]
1232 ; CHECK-NEXT: [[GUARD_COND:%.*]] = and i1 [[UNRELATED_COND_AND_1]], [[UNRELATED_COND_3]]
1233 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
1234 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[GUARD_COND]], [[WIDENABLE_COND]]
1235 ; CHECK-NEXT: br i1 [[EXIPLICIT_GUARD_COND]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
1236 ;
1237 entry:
1238 %tmp5 = icmp eq i32 %n, 0
1239 br i1 %tmp5, label %exit, label %loop.preheader
1240
1241 loop.preheader: ; preds = %entry
1242 br label %loop
1243
1244 loop: ; preds = %guarded, %loop.preheader
1245 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
1246 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
1247 %unrelated.cond.1 = icmp eq i32 %x1, %i
1248 %unrelated.cond.2 = icmp eq i32 %x2, %i
1249 %unrelated.cond.3 = icmp eq i32 %x3, %i
1250 %unrelated.cond.and.1 = and i1 %unrelated.cond.1, %unrelated.cond.2
1251 %guard.cond = and i1 %unrelated.cond.and.1, %unrelated.cond.3
1252 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
1253 %exiplicit_guard_cond = and i1 %guard.cond, %widenable_cond
1254 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
1255
1256 deopt: ; preds = %loop
1257 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
1258 ret i32 %deoptcall
1259
1260 guarded: ; preds = %loop
1261 %i.i64 = zext i32 %i to i64
1262 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
1263 %array.i = load i32, i32* %array.i.ptr, align 4
1264 %loop.acc.next = add i32 %loop.acc, %array.i
1265 %i.next = add nuw i32 %i, 1
1266 %continue = icmp ult i32 %i.next, %n
1267 br i1 %continue, label %loop, label %exit
1268
1269 exit: ; preds = %guarded, %entry
1270 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
1271 ret i32 %result
1272 }
1273
1274 define i32 @signed_loop_start_to_n_loop_variant_bound(i32* %array, i32 %x, i32 %start, i32 %n) {
1275 ; CHECK-LABEL: @signed_loop_start_to_n_loop_variant_bound(
1276 ; CHECK-NEXT: entry:
1277 ; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
1278 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
1279 ; CHECK: loop.preheader:
1280 ; CHECK-NEXT: br label [[LOOP:%.*]]
1281 ; CHECK: loop:
1282 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
1283 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ [[START:%.*]], [[LOOP_PREHEADER]] ]
1284 ; CHECK-NEXT: [[BOUND:%.*]] = add i32 [[I]], [[X:%.*]]
1285 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[BOUND]]
1286 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
1287 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
1288 ; CHECK-NEXT: br i1 [[EXIPLICIT_GUARD_COND]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
1289 ;
1290 entry:
1291 %tmp5 = icmp sle i32 %n, 0
1292 br i1 %tmp5, label %exit, label %loop.preheader
1293
1294 loop.preheader: ; preds = %entry
1295 br label %loop
1296
1297 loop: ; preds = %guarded, %loop.preheader
1298 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
1299 %i = phi i32 [ %i.next, %guarded ], [ %start, %loop.preheader ]
1300 %bound = add i32 %i, %x
1301 %within.bounds = icmp ult i32 %i, %bound
1302 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
1303 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
1304 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
1305
1306 deopt: ; preds = %loop
1307 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
1308 ret i32 %deoptcall
1309
1310 guarded: ; preds = %loop
1311 %i.i64 = zext i32 %i to i64
1312 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
1313 %array.i = load i32, i32* %array.i.ptr, align 4
1314 %loop.acc.next = add i32 %loop.acc, %array.i
1315 %i.next = add nsw i32 %i, 1
1316 %continue = icmp slt i32 %i.next, %n
1317 br i1 %continue, label %loop, label %exit
1318
1319 exit: ; preds = %guarded, %entry
1320 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
1321 ret i32 %result
1322 }
1323
1324 define i32 @signed_loop_start_to_n_non_monotonic_predicate(i32* %array, i32 %x, i32 %start, i32 %n) {
1325 ; CHECK-LABEL: @signed_loop_start_to_n_non_monotonic_predicate(
1326 ; CHECK-NEXT: entry:
1327 ; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
1328 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
1329 ; CHECK: loop.preheader:
1330 ; CHECK-NEXT: br label [[LOOP:%.*]]
1331 ; CHECK: loop:
1332 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
1333 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ [[START:%.*]], [[LOOP_PREHEADER]] ]
1334 ; CHECK-NEXT: [[GUARD_COND:%.*]] = icmp eq i32 [[I]], [[X:%.*]]
1335 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
1336 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[GUARD_COND]], [[WIDENABLE_COND]]
1337 ; CHECK-NEXT: br i1 [[EXIPLICIT_GUARD_COND]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
1338 ;
1339 entry:
1340 %tmp5 = icmp sle i32 %n, 0
1341 br i1 %tmp5, label %exit, label %loop.preheader
1342
1343 loop.preheader: ; preds = %entry
1344 br label %loop
1345
1346 loop: ; preds = %guarded, %loop.preheader
1347 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
1348 %i = phi i32 [ %i.next, %guarded ], [ %start, %loop.preheader ]
1349 %guard.cond = icmp eq i32 %i, %x
1350 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
1351 %exiplicit_guard_cond = and i1 %guard.cond, %widenable_cond
1352 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
1353
1354 deopt: ; preds = %loop
1355 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
1356 ret i32 %deoptcall
1357
1358 guarded: ; preds = %loop
1359 %i.i64 = zext i32 %i to i64
1360 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
1361 %array.i = load i32, i32* %array.i.ptr, align 4
1362 %loop.acc.next = add i32 %loop.acc, %array.i
1363 %i.next = add nsw i32 %i, 1
1364 %continue = icmp slt i32 %i.next, %n
1365 br i1 %continue, label %loop, label %exit
1366
1367 exit: ; preds = %guarded, %entry
1368 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
1369 ret i32 %result
1370 }
1371
1372 define i32 @unsigned_loop_0_to_n_hoist_length(i32* %array, i16 %length.i16, i32 %n) {
1373 ; CHECK-LABEL: @unsigned_loop_0_to_n_hoist_length(
1374 ; CHECK-NEXT: entry:
1375 ; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
1376 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
1377 ; CHECK: loop.preheader:
1378 ; CHECK-NEXT: [[TMP0:%.*]] = zext i16 [[LENGTH_I16:%.*]] to i32
1379 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ule i32 [[N]], [[TMP0]]
1380 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i32 0, [[TMP0]]
1381 ; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[TMP1]]
1382 ; CHECK-NEXT: br label [[LOOP:%.*]]
1383 ; CHECK: loop:
1384 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
1385 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
1386 ; CHECK-NEXT: [[LENGTH:%.*]] = zext i16 [[LENGTH_I16]] to i32
1387 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[LENGTH]]
1388 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
1389 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
1390 ; CHECK-NEXT: [[TMP4:%.*]] = and i1 [[TMP3]], [[WIDENABLE_COND]]
1391 ; CHECK-NEXT: br i1 [[TMP4]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
1392 ;
1393 entry:
1394 %tmp5 = icmp eq i32 %n, 0
1395 br i1 %tmp5, label %exit, label %loop.preheader
1396
1397 loop.preheader: ; preds = %entry
1398 br label %loop
1399
1400 loop: ; preds = %guarded, %loop.preheader
1401 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
1402 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
1403 %length = zext i16 %length.i16 to i32
1404 %within.bounds = icmp ult i32 %i, %length
1405 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
1406 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
1407 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
1408
1409 deopt: ; preds = %loop
1410 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
1411 ret i32 %deoptcall
1412
1413 guarded: ; preds = %loop
1414 %i.i64 = zext i32 %i to i64
1415 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
1416 %array.i = load i32, i32* %array.i.ptr, align 4
1417 %loop.acc.next = add i32 %loop.acc, %array.i
1418 %i.next = add nuw i32 %i, 1
1419 %continue = icmp ult i32 %i.next, %n
1420 br i1 %continue, label %loop, label %exit
1421
1422 exit: ; preds = %guarded, %entry
1423 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
1424 ret i32 %result
1425 }
1426
1427 define i32 @unsigned_loop_0_to_n_cant_hoist_length(i32* %array, i32 %length, i32 %divider, i32 %n) {
1428 ; CHECK-LABEL: @unsigned_loop_0_to_n_cant_hoist_length(
1429 ; CHECK-NEXT: entry:
1430 ; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0
1431 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
1432 ; CHECK: loop.preheader:
1433 ; CHECK-NEXT: br label [[LOOP:%.*]]
1434 ; CHECK: loop:
1435 ; CHECK-NEXT: [[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
1436 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[GUARDED]] ], [ 0, [[LOOP_PREHEADER]] ]
1437 ; CHECK-NEXT: [[LENGTH_UDIV:%.*]] = udiv i32 [[LENGTH:%.*]], [[DIVIDER:%.*]]
1438 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[LENGTH_UDIV]]
1439 ; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
1440 ; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WITHIN_BOUNDS]], [[WIDENABLE_COND]]
1441 ; CHECK-NEXT: br i1 [[EXIPLICIT_GUARD_COND]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
1442 ;
1443 entry:
1444 %tmp5 = icmp eq i32 %n, 0
1445 br i1 %tmp5, label %exit, label %loop.preheader
1446
1447 loop.preheader: ; preds = %entry
1448 br label %loop
1449
1450 loop: ; preds = %guarded, %loop.preheader
1451 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
1452 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
1453 %length.udiv = udiv i32 %length, %divider
1454 %within.bounds = icmp ult i32 %i, %length.udiv
1455 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
1456 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
1457 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
1458
1459 deopt: ; preds = %loop
1460 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
1461 ret i32 %deoptcall
1462
1463 guarded: ; preds = %loop
1464 %i.i64 = zext i32 %i to i64
1465 %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
1466 %array.i = load i32, i32* %array.i.ptr, align 4
1467 %loop.acc.next = add i32 %loop.acc, %array.i
1468 %i.next = add nuw i32 %i, 1
1469 %continue = icmp ult i32 %i.next, %n
1470 br i1 %continue, label %loop, label %exit
1471
1472 exit: ; preds = %guarded, %entry
1473 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
1474 ret i32 %result
1475 }
1476
1477 declare i32 @llvm.experimental.deoptimize.i32(...)
1478
1479 ; Function Attrs: inaccessiblememonly nounwind
1480 declare i1 @llvm.experimental.widenable.condition() #0
1481
1482 attributes #0 = { inaccessiblememonly nounwind }
1483
1484 !0 = !{!"branch_weights", i32 1048576, i32 1}
1485 !1 = !{i32 1, i32 -2147483648}