• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -inline -sroa -S | FileCheck %s
2; RUN: opt < %s -passes='cgscc(inline,function(sroa))' -S | FileCheck %s
3target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
4
5define i32 @test1f(i32 %i) {
6        ret i32 %i
7}
8
9define i32 @test1(i32 %W) {
10        %X = call i32 @test1f(i32 7)
11        %Y = add i32 %X, %W
12        ret i32 %Y
13; CHECK-LABEL: @test1(
14; CHECK-NEXT: %Y = add i32 7, %W
15; CHECK-NEXT: ret i32 %Y
16}
17
18
19
20; rdar://7339069
21
22%T = type { i32, i32 }
23
24; CHECK-NOT: @test2f(
25define internal %T* @test2f(i1 %cond, %T* %P) {
26  br i1 %cond, label %T, label %F
27
28T:
29  %A = getelementptr %T, %T* %P, i32 0, i32 0
30  store i32 42, i32* %A
31  ret %T* %P
32
33F:
34  ret %T* %P
35}
36
37define i32 @test2(i1 %cond) {
38  %A = alloca %T
39
40  %B = call %T* @test2f(i1 %cond, %T* %A)
41  %C = getelementptr %T, %T* %B, i32 0, i32 0
42  %D = load i32, i32* %C
43  ret i32 %D
44
45; CHECK-LABEL: @test2(
46; CHECK-NOT: = alloca
47; CHECK: ret i32
48}
49
50declare void @barrier() noduplicate
51
52define internal i32 @f() {
53  call void @barrier() noduplicate
54  ret i32 1
55}
56
57define i32 @g() {
58  call void @barrier() noduplicate
59  ret i32 2
60}
61
62define internal i32 @h() {
63  call void @barrier() noduplicate
64  ret i32 3
65}
66
67define i32 @test3() {
68  %b = call i32 @f()
69  ret i32 %b
70}
71
72; The call to @f cannot be inlined as there is another callsite
73; calling @f, and @f contains a noduplicate call.
74;
75; The call to @g cannot be inlined as it has external linkage.
76;
77; The call to @h *can* be inlined.
78
79; CHECK-LABEL: @test(
80define i32 @test() {
81; CHECK: call i32 @f()
82  %a = call i32 @f()
83; CHECK: call i32 @g()
84  %b = call i32 @g()
85; CHECK-NOT: call i32 @h()
86  %c = call i32 @h()
87
88  %d = add i32 %a, %b
89  %e = add i32 %d, %c
90
91  ret i32 %e
92; CHECK: }
93}
94
95; Inliner shouldn't delete calls it can't inline, even if they're trivially dead
96; CHECK-LABEL: @outer4(
97define void @outer4(void ()* %inner4) {
98entry:
99; CHECK: call void %inner4()
100  call void %inner4() nounwind readnone
101  ret void
102}
103
104declare void @inner5_inner()
105
106define void @inner5(void ()* %x) {
107  call void %x() nounwind readnone
108  ret void
109}
110
111; Inliner shouldn't delete calls it can't inline, even if they're trivially dead and temporarily indirect
112; CHECK-LABEL: @outer5(
113define void @outer5() {
114; CHECK: call void @inner5_inner(
115  call void @inner5(void ()* @inner5_inner)
116  ret void
117}
118