blob: c220efa50a6c9f6b91f25ad80d75578c338ce778 [file] [log] [blame]
Sanjoy Dasa1837a32015-01-16 01:03:22 +00001; RUN: opt -irce -S < %s | FileCheck %s
2
3define void @single_access_with_preloop(i32 *%arr, i32 *%a_len_ptr, i32 %n, i32 %offset) {
4 entry:
5 %len = load i32* %a_len_ptr, !range !0
6 %first.itr.check = icmp sgt i32 %n, 0
7 br i1 %first.itr.check, label %loop, label %exit
8
9 loop:
10 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
11 %idx.next = add i32 %idx, 1
12 %array.idx = add i32 %idx, %offset
13 %abc.high = icmp slt i32 %array.idx, %len
14 %abc.low = icmp sge i32 %array.idx, 0
15 %abc = and i1 %abc.low, %abc.high
Sanjoy Dasdcf26512015-01-27 21:38:12 +000016 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1
Sanjoy Dasa1837a32015-01-16 01:03:22 +000017
18 in.bounds:
19 %addr = getelementptr i32* %arr, i32 %array.idx
20 store i32 0, i32* %addr
21 %next = icmp slt i32 %idx.next, %n
22 br i1 %next, label %loop, label %exit
23
24 out.of.bounds:
25 ret void
26
27 exit:
28 ret void
29}
30
31; CHECK-LABEL: loop.preheader:
Sanjoy Das7fc60da2015-02-21 22:07:32 +000032; CHECK: [[not_safe_start:[^ ]+]] = add i32 %offset, -1
33; CHECK: [[not_n:[^ ]+]] = sub i32 -1, %n
34; CHECK: [[not_exit_preloop_at_cond:[^ ]+]] = icmp sgt i32 [[not_safe_start]], [[not_n]]
35; CHECK: [[not_exit_preloop_at:[^ ]+]] = select i1 [[not_exit_preloop_at_cond]], i32 [[not_safe_start]], i32 [[not_n]]
36; CHECK: [[exit_preloop_at:[^ ]+]] = sub i32 -1, [[not_exit_preloop_at]]
37
38; CHECK: [[not_safe_end:[^ ]+]] = sub i32 [[not_safe_start]], %len
39; CHECK: [[not_exit_mainloop_at_cond:[^ ]+]] = icmp sgt i32 [[not_safe_end]], [[not_n]]
40; CHECK: [[not_exit_mainloop_at:[^ ]+]] = select i1 [[not_exit_mainloop_at_cond]], i32 [[not_safe_end]], i32 [[not_n]]
41; CHECK: [[exit_mainloop_at:[^ ]+]] = sub i32 -1, [[not_exit_mainloop_at]]
Sanjoy Dasa1837a32015-01-16 01:03:22 +000042
43; CHECK-LABEL: in.bounds:
44; CHECK: [[continue_mainloop_cond:[^ ]+]] = icmp slt i32 %idx.next, [[exit_mainloop_at]]
45; CHECK: br i1 [[continue_mainloop_cond]], label %loop, label %main.exit.selector
46
47; CHECK-LABEL: main.exit.selector:
48; CHECK: [[mainloop_its_left:[^ ]+]] = icmp slt i32 %idx.next, %n
49; CHECK: br i1 [[mainloop_its_left]], label %main.pseudo.exit, label %exit.loopexit
50
51; CHECK-LABEL: in.bounds.preloop:
52; CHECK: [[continue_preloop_cond:[^ ]+]] = icmp slt i32 %idx.next.preloop, [[exit_preloop_at]]
53; CHECK: br i1 [[continue_preloop_cond]], label %loop.preloop, label %preloop.exit.selector
54
55; CHECK-LABEL: preloop.exit.selector:
56; CHECK: [[preloop_its_left:[^ ]+]] = icmp slt i32 %idx.next.preloop, %n
57; CHECK: br i1 [[preloop_its_left]], label %preloop.pseudo.exit, label %exit.loopexit
58
59; CHECK-LABEL: in.bounds.postloop:
60; CHECK: %next.postloop = icmp slt i32 %idx.next.postloop, %n
61; CHECK: br i1 %next.postloop, label %loop.postloop, label %exit.loopexit
62
63!0 = !{i32 0, i32 2147483647}
Sanjoy Dasdcf26512015-01-27 21:38:12 +000064!1 = !{!"branch_weights", i32 64, i32 4}