• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -verify-loop-info -irce -irce-print-range-checks -irce-print-changed-loops %s -S 2>&1 | FileCheck %s
2; RUN: opt -verify-loop-info -passes='require<branch-prob>,irce' -irce-print-range-checks -irce-print-changed-loops %s -S 2>&1 | FileCheck %s
3
4; Make sure that we can pick up both range checks.
5define void @test_01(i32 *%arr, i32* %a_len_ptr, i32* %size_ptr) {
6
7; CHECK-LABEL: @test_01(
8
9entry:
10  %len = load i32, i32* %a_len_ptr, !range !0
11  %size = load i32, i32* %size_ptr
12  %first_iter_check = icmp sle i32 %size, 0
13  br i1 %first_iter_check, label %exit, label %loop
14
15loop:
16  %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]
17  %rc1 = icmp slt i32 %iv, %len
18  %rc2 = icmp slt i32 %iv, %size
19  ; CHECK: %rc = and i1 true, true
20  %rc = and i1 %rc1, %rc2
21  br i1 %rc, label %backedge, label %out_of_bounds
22
23
24backedge:
25  %iv.next = add i32 %iv, 1
26  %arr_el_ptr = getelementptr i32, i32* %arr, i32 %iv
27  %el = load i32, i32* %arr_el_ptr
28  %loopcond = icmp ne i32 %iv, %size
29  br i1 %loopcond, label %loop, label %exit
30
31exit:
32  ret void
33
34out_of_bounds:
35  ret void
36}
37
38; Same as test_01, unsigned predicates.
39define void @test_02(i32 *%arr, i32* %a_len_ptr, i32* %size_ptr) {
40
41; CHECK-LABEL: @test_02(
42
43entry:
44  %len = load i32, i32* %a_len_ptr, !range !0
45  %size = load i32, i32* %size_ptr
46  %first_iter_check = icmp sle i32 %size, 0
47  br i1 %first_iter_check, label %exit, label %loop
48
49loop:
50  %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]
51  %rc1 = icmp ult i32 %iv, %len
52  %rc2 = icmp ult i32 %iv, %size
53  ; CHECK: %rc = and i1 true, true
54  %rc = and i1 %rc1, %rc2
55  br i1 %rc, label %backedge, label %out_of_bounds
56
57
58backedge:
59  %iv.next = add i32 %iv, 1
60  %arr_el_ptr = getelementptr i32, i32* %arr, i32 %iv
61  %el = load i32, i32* %arr_el_ptr
62  %loopcond = icmp ne i32 %iv, %size
63  br i1 %loopcond, label %loop, label %exit
64
65exit:
66  ret void
67
68out_of_bounds:
69  ret void
70}
71
72define void @test_03(i32 *%arr, i32* %a_len_ptr, i32* %size_ptr) {
73
74; CHECK-LABEL: @test_03(
75
76entry:
77  %len = load i32, i32* %a_len_ptr, !range !0
78  %size = load i32, i32* %size_ptr
79  %first_iter_check = icmp eq i32 %size, 0
80  br i1 %first_iter_check, label %exit, label %loop
81
82loop:
83  %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]
84  %rc1 = icmp slt i32 %iv, %len
85  %rc2 = icmp slt i32 %iv, %size
86  ; CHECK: %rc = and i1 true, true
87  %rc = and i1 %rc1, %rc2
88  br i1 %rc, label %backedge, label %out_of_bounds
89
90
91backedge:
92  %iv.next = add i32 %iv, 1
93  %arr_el_ptr = getelementptr i32, i32* %arr, i32 %iv
94  %el = load i32, i32* %arr_el_ptr
95  %loopcond = icmp ne i32 %iv, %len
96  br i1 %loopcond, label %loop, label %exit
97
98exit:
99  ret void
100
101out_of_bounds:
102  ret void
103}
104
105define void @test_04(i32 *%arr, i32* %a_len_ptr, i32* %size_ptr) {
106
107; CHECK-LABEL: @test_04(
108
109entry:
110  %len = load i32, i32* %a_len_ptr, !range !0
111  %size = load i32, i32* %size_ptr
112  %first_iter_check = icmp eq i32 %size, 0
113  br i1 %first_iter_check, label %exit, label %loop
114
115loop:
116  %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]
117  %rc1 = icmp ult i32 %iv, %len
118  %rc2 = icmp ult i32 %iv, %size
119  ; CHECK: %rc = and i1 true, true
120  %rc = and i1 %rc1, %rc2
121  br i1 %rc, label %backedge, label %out_of_bounds
122
123
124backedge:
125  %iv.next = add i32 %iv, 1
126  %arr_el_ptr = getelementptr i32, i32* %arr, i32 %iv
127  %el = load i32, i32* %arr_el_ptr
128  %loopcond = icmp ne i32 %iv, %len
129  br i1 %loopcond, label %loop, label %exit
130
131exit:
132  ret void
133
134out_of_bounds:
135  ret void
136}
137
138!0 = !{i32 0, i32 2147483647}
139!1 = !{!"branch_weights", i32 64, i32 4}
140