• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -irce -S < %s | FileCheck %s
2
3define void @decrementing_loop(i32 *%arr, i32 *%a_len_ptr, i32 %n) {
4 entry:
5  %len = load i32, i32* %a_len_ptr, !range !0
6  %first.itr.check = icmp sgt i32 %n, 0
7  %start = sub i32 %n, 1
8  br i1 %first.itr.check, label %loop, label %exit
9
10 loop:
11  %idx = phi i32 [ %start, %entry ] , [ %idx.dec, %in.bounds ]
12  %idx.dec = sub i32 %idx, 1
13  %abc.high = icmp slt i32 %idx, %len
14  %abc.low = icmp sge i32 %idx, 0
15  %abc = and i1 %abc.low, %abc.high
16  br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1
17
18 in.bounds:
19  %addr = getelementptr i32, i32* %arr, i32 %idx
20  store i32 0, i32* %addr
21  %next = icmp sgt i32 %idx.dec, -1
22  br i1 %next, label %loop, label %exit
23
24 out.of.bounds:
25  ret void
26
27 exit:
28  ret void
29
30; CHECK: loop.preheader:
31; CHECK:   [[not_len:[^ ]+]] = sub i32 -1, %len
32; CHECK:   [[not_n:[^ ]+]] = sub i32 -1, %n
33; CHECK:   [[not_len_hiclamp_cmp:[^ ]+]] = icmp sgt i32 [[not_len]], [[not_n]]
34; CHECK:   [[not_len_hiclamp:[^ ]+]] = select i1 [[not_len_hiclamp_cmp]], i32 [[not_len]], i32 [[not_n]]
35; CHECK:   [[len_hiclamp:[^ ]+]] = sub i32 -1, [[not_len_hiclamp]]
36; CHECK:   [[not_exit_preloop_at_cmp:[^ ]+]] = icmp sgt i32 [[len_hiclamp]], 0
37; CHECK:   [[not_exit_preloop_at:[^ ]+]] = select i1 [[not_exit_preloop_at_cmp]], i32 [[len_hiclamp]], i32 0
38; CHECK:   %exit.preloop.at = add i32 [[not_exit_preloop_at]], -1
39}
40
41!0 = !{i32 0, i32 2147483647}
42!1 = !{!"branch_weights", i32 64, i32 4}
43