1; RUN: opt -inline < %s -S -o - -inline-threshold=10 | FileCheck %s
2
3target datalayout = "p:32:32-p1:64:64-p2:16:16-n16:32:64"
4
5define i32 @outer1() {
6; CHECK-LABEL: @outer1(
7; CHECK-NOT: call i32
8; CHECK: ret i32
9
10  %ptr = alloca i32
11  %ptr1 = getelementptr inbounds i32, i32* %ptr, i32 0
12  %ptr2 = getelementptr inbounds i32, i32* %ptr, i32 42
13  %result = call i32 @inner1(i32* %ptr1, i32* %ptr2)
14  ret i32 %result
15}
16
17define i32 @inner1(i32* %begin, i32* %end) {
18  call void @extern()
19  %begin.i = ptrtoint i32* %begin to i32
20  %end.i = ptrtoint i32* %end to i32
21  %distance = sub i32 %end.i, %begin.i
22  %icmp = icmp sle i32 %distance, 42
23  br i1 %icmp, label %then, label %else
24
25then:
26  ret i32 3
27
28else:
29  %t = load i32, i32* %begin
30  ret i32 %t
31}
32
33define i32 @outer2(i32* %ptr) {
34; Test that an inbounds GEP disables this -- it isn't safe in general as
35; wrapping changes the behavior of lessthan and greaterthan comparisons.
36; CHECK-LABEL: @outer2(
37; CHECK: call i32 @inner2
38; CHECK: ret i32
39
40  %ptr1 = getelementptr i32, i32* %ptr, i32 0
41  %ptr2 = getelementptr i32, i32* %ptr, i32 42
42  %result = call i32 @inner2(i32* %ptr1, i32* %ptr2)
43  ret i32 %result
44}
45
46define i32 @inner2(i32* %begin, i32* %end) {
47  call void @extern()
48  %begin.i = ptrtoint i32* %begin to i32
49  %end.i = ptrtoint i32* %end to i32
50  %distance = sub i32 %end.i, %begin.i
51  %icmp = icmp sle i32 %distance, 42
52  br i1 %icmp, label %then, label %else
53
54then:
55  ret i32 3
56
57else:
58  %t = load i32, i32* %begin
59  ret i32 %t
60}
61
62; The inttoptrs are free since it is a smaller integer to a larger
63; pointer size
64define i32 @inttoptr_free_cost(i32 %a, i32 %b, i32 %c) {
65  call void @extern()
66  %p1 = inttoptr i32 %a to i32 addrspace(1)*
67  %p2 = inttoptr i32 %b to i32 addrspace(1)*
68  %p3 = inttoptr i32 %c to i32 addrspace(1)*
69  %t1 = load i32, i32 addrspace(1)* %p1
70  %t2 = load i32, i32 addrspace(1)* %p2
71  %t3 = load i32, i32 addrspace(1)* %p3
72  %s = add i32 %t1, %t2
73  %s1 = add i32 %s, %t3
74  ret i32 %s1
75}
76
77define i32 @inttoptr_free_cost_user(i32 %begin, i32 %end) {
78; CHECK-LABEL: @inttoptr_free_cost_user(
79; CHECK-NOT: call i32
80  %x = call i32 @inttoptr_free_cost(i32 %begin, i32 %end, i32 9)
81  ret i32 %x
82}
83
84; The inttoptrs have a cost since it is a larger integer to a smaller
85; pointer size
86define i32 @inttoptr_cost_smaller_ptr(i32 %a, i32 %b, i32 %c) {
87  call void @extern()
88  %p1 = inttoptr i32 %a to i32 addrspace(2)*
89  %p2 = inttoptr i32 %b to i32 addrspace(2)*
90  %p3 = inttoptr i32 %c to i32 addrspace(2)*
91  %t1 = load i32, i32 addrspace(2)* %p1
92  %t2 = load i32, i32 addrspace(2)* %p2
93  %t3 = load i32, i32 addrspace(2)* %p3
94  %s = add i32 %t1, %t2
95  %s1 = add i32 %s, %t3
96  ret i32 %s1
97}
98
99define i32 @inttoptr_cost_smaller_ptr_user(i32 %begin, i32 %end) {
100; CHECK-LABEL: @inttoptr_cost_smaller_ptr_user(
101; CHECK: call i32
102  %x = call i32 @inttoptr_cost_smaller_ptr(i32 %begin, i32 %end, i32 9)
103  ret i32 %x
104}
105
106declare void @extern()