• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -instcombine -S < %s | FileCheck %s
2
3declare void @llvm.init.trampoline(i8*, i8*, i8*)
4declare i8* @llvm.adjust.trampoline(i8*)
5declare i32 @f(i8 * nest, i32)
6
7; Most common case
8define i32 @test0(i32 %n) !dbg !4 {
9  %alloca = alloca [10 x i8], align 16
10  %gep = getelementptr [10 x i8], [10 x i8]* %alloca, i32 0, i32 0
11  call void @llvm.init.trampoline(i8* %gep, i8* bitcast (i32 (i8*, i32)* @f to i8*),
12                                  i8* null)
13  %tramp = call i8* @llvm.adjust.trampoline(i8* %gep)
14  %function = bitcast i8* %tramp to i32(i32)*
15  %ret = call i32 %function(i32 %n), !dbg !10
16  ret i32 %ret
17
18; CHECK: define i32 @test0(i32 %n) !dbg !4 {
19; CHECK: %ret = call i32 @f(i8* nest null, i32 %n), !dbg !10
20}
21
22define i32 @test1(i32 %n, i8* %trampmem) {
23  call void @llvm.init.trampoline(i8* %trampmem,
24                                  i8* bitcast (i32 (i8*, i32)* @f to i8*),
25                                  i8* null)
26  %tramp = call i8* @llvm.adjust.trampoline(i8* %trampmem)
27  %function = bitcast i8* %tramp to i32(i32)*
28  %ret = call i32 %function(i32 %n)
29  ret i32 %ret
30; CHECK: define i32 @test1(i32 %n, i8* %trampmem) {
31; CHECK: %ret = call i32 @f(i8* nest null, i32 %n)
32}
33
34define i32 @test2(i32 %n, i8* %trampmem) {
35  %tramp = call i8* @llvm.adjust.trampoline(i8* %trampmem)
36  %functiona = bitcast i8* %tramp to i32(i32)*
37  %ret = call i32 %functiona(i32 %n)
38  ret i32 %ret
39; CHECK: define i32 @test2(i32 %n, i8* %trampmem) {
40; CHECK: %ret = call i32 %functiona(i32 %n)
41}
42
43define i32 @test3(i32 %n, i8* %trampmem) {
44  call void @llvm.init.trampoline(i8* %trampmem,
45                                  i8* bitcast (i32 (i8*, i32)* @f to i8*),
46                                  i8* null)
47
48; CHECK: define i32 @test3(i32 %n, i8* %trampmem) {
49; CHECK: %ret0 = call i32 @f(i8* nest null, i32 %n)
50  %tramp0 = call i8* @llvm.adjust.trampoline(i8* %trampmem)
51  %function0 = bitcast i8* %tramp0 to i32(i32)*
52  %ret0 = call i32 %function0(i32 %n)
53
54  ;; Not optimized since previous call could be writing.
55  %tramp1 = call i8* @llvm.adjust.trampoline(i8* %trampmem)
56  %function1 = bitcast i8* %tramp1 to i32(i32)*
57  %ret1 = call i32 %function1(i32 %n)
58; CHECK: %ret1 = call i32 %function1(i32 %n)
59
60  ret i32 %ret1
61}
62
63define i32 @test4(i32 %n) {
64  %alloca = alloca [10 x i8], align 16
65  %gep = getelementptr [10 x i8], [10 x i8]* %alloca, i32 0, i32 0
66  call void @llvm.init.trampoline(i8* %gep, i8* bitcast (i32 (i8*, i32)* @f to i8*),
67                                  i8* null)
68
69  %tramp0 = call i8* @llvm.adjust.trampoline(i8* %gep)
70  %function0 = bitcast i8* %tramp0 to i32(i32)*
71  %ret0 = call i32 %function0(i32 %n)
72
73  %tramp1 = call i8* @llvm.adjust.trampoline(i8* %gep)
74  %function1 = bitcast i8* %tramp0 to i32(i32)*
75  %ret1 = call i32 %function1(i32 %n)
76
77  %tramp2 = call i8* @llvm.adjust.trampoline(i8* %gep)
78  %function2 = bitcast i8* %tramp2 to i32(i32)*
79  %ret2 = call i32 %function2(i32 %n)
80
81  ret i32 %ret2
82
83; CHECK: define i32 @test4(i32 %n) {
84; CHECK: %ret0 = call i32 @f(i8* nest null, i32 %n)
85; CHECK: %ret1 = call i32 @f(i8* nest null, i32 %n)
86; CHECK: %ret2 = call i32 @f(i8* nest null, i32 %n)
87}
88
89!llvm.dbg.cu = !{!0}
90!llvm.module.flags = !{!3}
91
92!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.0 (trunk 127710)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2)
93!1 = !DIFile(filename: "string.h", directory: "Game")
94!2 = !{}
95!3 = !{i32 1, !"Debug Info Version", i32 3}
96!4 = distinct !DISubprogram(name: "passthru", scope: !1, file: !1, line: 79, type: !5, isLocal: true, isDefinition: true, scopeLine: 79, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !8)
97!5 = !DISubroutineType(types: !6)
98!6 = !{!7}
99!7 = !DIDerivedType(tag: DW_TAG_pointer_type, scope: !0, baseType: null, size: 64, align: 64)
100!8 = !{!9}
101!9 = !DILocalVariable(name: "a", arg: 1, scope: !4, file: !1, line: 78, type: !7)
102!10 = !DILocation(line: 78, column: 28, scope: !4)
103