• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -S -irce < %s | FileCheck %s
2
3define void @f_0(i32 *%arr, i32 *%a_len_ptr, i32 %n, i1* %cond_buf) {
4; CHECK-LABEL: @f_0(
5
6; CHECK-LABEL: loop.preheader:
7; CHECK: [[not_n:[^ ]+]] = sub i32 -1, %n
8; CHECK: [[not_safe_range_end:[^ ]+]] = sub i32 3, %len
9; CHECK: [[not_exit_main_loop_at_hiclamp_cmp:[^ ]+]] = icmp sgt i32 [[not_n]], [[not_safe_range_end]]
10; CHECK: [[not_exit_main_loop_at_hiclamp:[^ ]+]] = select i1 [[not_exit_main_loop_at_hiclamp_cmp]], i32 [[not_n]], i32 [[not_safe_range_end]]
11; CHECK: [[exit_main_loop_at_hiclamp:[^ ]+]] = sub i32 -1, [[not_exit_main_loop_at_hiclamp]]
12; CHECK: [[exit_main_loop_at_loclamp_cmp:[^ ]+]] = icmp sgt i32 [[exit_main_loop_at_hiclamp]], 0
13; CHECK: [[exit_main_loop_at_loclamp:[^ ]+]] = select i1 [[exit_main_loop_at_loclamp_cmp]], i32 [[exit_main_loop_at_hiclamp]], i32 0
14; CHECK: [[enter_main_loop:[^ ]+]] = icmp slt i32 0, [[exit_main_loop_at_loclamp]]
15; CHECK: br i1 [[enter_main_loop]], label %loop, label %main.pseudo.exit
16
17 entry:
18  %len = load i32, i32* %a_len_ptr, !range !0
19  %first.itr.check = icmp sgt i32 %n, 0
20  br i1 %first.itr.check, label %loop, label %exit
21
22 loop:
23  %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
24  %idx.next = add i32 %idx, 1
25  %idx.for.abc = add i32 %idx, 4
26  %abc.actual = icmp slt i32 %idx.for.abc, %len
27  %cond = load volatile i1, i1* %cond_buf
28  %abc = and i1 %cond, %abc.actual
29  br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1
30
31; CHECK: loop:
32; CHECK:  %cond = load volatile i1, i1* %cond_buf
33; CHECK:  %abc = and i1 %cond, true
34; CHECK:  br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1
35
36 in.bounds:
37  %addr = getelementptr i32, i32* %arr, i32 %idx.for.abc
38  store i32 0, i32* %addr
39  %next = icmp slt i32 %idx.next, %n
40  br i1 %next, label %loop, label %exit
41
42 out.of.bounds:
43  ret void
44
45 exit:
46  ret void
47}
48
49define void @f_1(
50    i32* %arr_a, i32* %a_len_ptr, i32* %arr_b, i32* %b_len_ptr, i32 %n) {
51; CHECK-LABEL: @f_1(
52
53; CHECK-LABEL: loop.preheader:
54; CHECK: [[not_len_b:[^ ]+]] = sub i32 -1, %len.b
55; CHECK: [[not_len_a:[^ ]+]] = sub i32 -1, %len.a
56; CHECK: [[smax_not_len_cond:[^ ]+]] = icmp sgt i32 [[not_len_b]], [[not_len_a]]
57; CHECK: [[smax_not_len:[^ ]+]] = select i1 [[smax_not_len_cond]], i32 [[not_len_b]], i32 [[not_len_a]]
58; CHECK: [[not_n:[^ ]+]] = sub i32 -1, %n
59; CHECK: [[not_upper_limit_cond_loclamp:[^ ]+]] = icmp sgt i32 [[smax_not_len]], [[not_n]]
60; CHECK: [[not_upper_limit_loclamp:[^ ]+]] = select i1 [[not_upper_limit_cond_loclamp]], i32 [[smax_not_len]], i32 [[not_n]]
61; CHECK: [[upper_limit_loclamp:[^ ]+]] = sub i32 -1, [[not_upper_limit_loclamp]]
62; CHECK: [[upper_limit_cmp:[^ ]+]] = icmp sgt i32 [[upper_limit_loclamp]], 0
63; CHECK: [[upper_limit:[^ ]+]] = select i1 [[upper_limit_cmp]], i32 [[upper_limit_loclamp]], i32 0
64
65 entry:
66  %len.a = load i32, i32* %a_len_ptr, !range !0
67  %len.b = load i32, i32* %b_len_ptr, !range !0
68  %first.itr.check = icmp sgt i32 %n, 0
69  br i1 %first.itr.check, label %loop, label %exit
70
71 loop:
72  %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
73  %idx.next = add i32 %idx, 1
74  %abc.a = icmp slt i32 %idx, %len.a
75  %abc.b = icmp slt i32 %idx, %len.b
76  %abc = and i1 %abc.a, %abc.b
77  br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1
78
79; CHECK: loop:
80; CHECK:   %abc = and i1 true, true
81; CHECK:   br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1
82
83 in.bounds:
84  %addr.a = getelementptr i32, i32* %arr_a, i32 %idx
85  store i32 0, i32* %addr.a
86  %addr.b = getelementptr i32, i32* %arr_b, i32 %idx
87  store i32 -1, i32* %addr.b
88  %next = icmp slt i32 %idx.next, %n
89  br i1 %next, label %loop, label %exit
90
91 out.of.bounds:
92  ret void
93
94 exit:
95  ret void
96}
97
98!0 = !{i32 0, i32 2147483647}
99!1 = !{!"branch_weights", i32 64, i32 4}
100