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