1; RUN: opt < %s -inline -S | FileCheck %s
2; RUN: opt < %s -passes='cgscc(inline)' -S | FileCheck %s
3
4@a = global i32 4
5@_ZTIi = external global i8*
6
7; CHECK-LABEL: callSimpleFunction
8; CHECK: call i32 @simpleFunction
9define i32 @callSimpleFunction(i32 %idx, i32 %limit) {
10entry:
11  %cmp = icmp sge i32 %idx, %limit
12  br i1 %cmp, label %if.then, label %if.end
13
14if.then:
15  %s = call i32 @simpleFunction(i32 %idx)
16  store i32 %s, i32* @a
17  unreachable
18
19if.end:
20  ret i32 %idx
21}
22
23; CHECK-LABEL: callSmallFunction
24; CHECK-NOT: call i32 @smallFunction
25define i32 @callSmallFunction(i32 %idx, i32 %limit) {
26entry:
27  %cmp = icmp sge i32 %idx, %limit
28  br i1 %cmp, label %if.then, label %if.end
29
30if.then:
31  %s = call i32 @smallFunction(i32 %idx)
32  store i32 %s, i32* @a
33  unreachable
34
35if.end:
36  ret i32 %idx
37}
38
39; CHECK-LABEL: throwSimpleException
40; CHECK: invoke i32 @simpleFunction
41define i32 @throwSimpleException(i32 %idx, i32 %limit) #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
42entry:
43  %cmp = icmp sge i32 %idx, %limit
44  br i1 %cmp, label %if.then, label %if.end
45
46if.then:                                          ; preds = %entry
47  %exception = call i8* @__cxa_allocate_exception(i64 1) #0
48  invoke i32 @simpleFunction(i32 %idx)
49          to label %invoke.cont unwind label %lpad
50
51invoke.cont:                                      ; preds = %if.then
52  call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi  to i8*), i8* null) #1
53  unreachable
54
55lpad:                                             ; preds = %if.then
56  %ll = landingpad { i8*, i32 }
57          cleanup
58  ret i32 %idx
59
60if.end:                                           ; preds = %entry
61  ret i32 %idx
62}
63
64; CHECK-LABEL: throwSmallException
65; CHECK-NOT: invoke i32 @smallFunction
66define i32 @throwSmallException(i32 %idx, i32 %limit) #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
67entry:
68  %cmp = icmp sge i32 %idx, %limit
69  br i1 %cmp, label %if.then, label %if.end
70
71if.then:                                          ; preds = %entry
72  %exception = call i8* @__cxa_allocate_exception(i64 1) #0
73  invoke i32 @smallFunction(i32 %idx)
74          to label %invoke.cont unwind label %lpad
75
76invoke.cont:                                      ; preds = %if.then
77  call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi  to i8*), i8* null) #1
78  unreachable
79
80lpad:                                             ; preds = %if.then
81  %ll = landingpad { i8*, i32 }
82          cleanup
83  ret i32 %idx
84
85if.end:                                           ; preds = %entry
86  ret i32 %idx
87}
88
89define i32 @simpleFunction(i32 %a) #0 {
90entry:
91  %a1 = load volatile i32, i32* @a
92  %x1 = add i32 %a1,  %a1
93  %a2 = load volatile i32, i32* @a
94  %x2 = add i32 %x1, %a2
95  %a3 = load volatile i32, i32* @a
96  %x3 = add i32 %x2, %a3
97  %a4 = load volatile i32, i32* @a
98  %x4 = add i32 %x3, %a4
99  %a5 = load volatile i32, i32* @a
100  %x5 = add i32 %x4, %a5
101  %a6 = load volatile i32, i32* @a
102  %x6 = add i32 %x5, %a6
103  %a7 = load volatile i32, i32* @a
104  %x7 = add i32 %x6, %a6
105  %a8 = load volatile i32, i32* @a
106  %x8 = add i32 %x7, %a8
107  %a9 = load volatile i32, i32* @a
108  %x9 = add i32 %x8, %a9
109  %a10 = load volatile i32, i32* @a
110  %x10 = add i32 %x9, %a10
111  %a11 = load volatile i32, i32* @a
112  %x11 = add i32 %x10, %a11
113  %a12 = load volatile i32, i32* @a
114  %x12 = add i32 %x11, %a12
115  %add = add i32 %x12, %a
116  ret i32 %add
117}
118
119define i32 @smallFunction(i32 %a) {
120entry:
121  %r = load volatile i32, i32* @a
122  ret i32 %r
123}
124
125attributes #0 = { nounwind }
126attributes #1 = { noreturn }
127
128declare i8* @__cxa_allocate_exception(i64)
129declare i32 @__gxx_personality_v0(...)
130declare void @__cxa_throw(i8*, i8*, i8*)
131
132