File: inline_call.ll

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (72 lines) | stat: -rw-r--r-- 2,528 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
; Check the optimizer doesn't crash at inlining the function top and all of its callees are inlined.
; RUN: opt < %s -O3 -S | FileCheck %s
; RUN: opt < %s -O3 -inline-enable-priority-order=true -S | FileCheck %s

define dso_local void (...)* @second(i8** %p) {
entry:
  %p.addr = alloca i8**, align 8
  store i8** %p, i8*** %p.addr, align 8
  %tmp = load i8**, i8*** %p.addr, align 8
  %tmp1 = load i8*, i8** %tmp, align 8
  %tmp2 = bitcast i8* %tmp1 to void (...)*
  ret void (...)* %tmp2
}

define dso_local void @top()  {
entry:
  ; CHECK: {{.*}} = {{.*}} call {{.*}} @ext
  ; CHECK-NOT: {{.*}} = {{.*}} call {{.*}} @third
  ; CHECK-NOT: {{.*}} = {{.*}} call {{.*}} @second
  ; CHECK-NOT: {{.*}} = {{.*}} call {{.*}} @wrapper
  %q = alloca i8*, align 8
  store i8* bitcast (void ()* @third to i8*), i8** %q, align 8
  %tmp = call void (...)* @second(i8** %q)
  ; The call to 'wrapper' here is to ensure that its function attributes
  ; i.e., returning its parameter and having no side effect, will be decuded
  ; before the next round of inlining happens to 'top' to expose the bug.
  %call =  call void (...)* @wrapper(void (...)* %tmp) 
  ; The indirect call here is to confuse the alias analyzer so that
  ; an incomplete graph will be built during the first round of inlining.
  ; This allows the current function to be processed before the actual 
  ; callee, i.e., the function 'run', is processed. Once it's simplified to 
  ; a direct call, it also enables an additional round of inlining with all
  ; function attributes deduced. 
  call void (...) %call()
  ret void
}

define dso_local void (...)* @gen() {
entry:
  %call = call void (...)* (...) @ext()
  ret void (...)* %call
}

declare dso_local void (...)* @ext(...) 

define dso_local void (...)* @wrapper(void (...)* %fn) {
entry:
  ret void (...)* %fn
}

define dso_local void @run(void (...)* %fn) {
entry:
  %fn.addr = alloca void (...)*, align 8
  %f = alloca void (...)*, align 8
  store void (...)* %fn, void (...)** %fn.addr, align 8
  %tmp = load void (...)*, void (...)** %fn.addr, align 8
  %call = call void (...)* @wrapper(void (...)* %tmp)
  store void (...)* %call, void (...)** %f, align 8
  %tmp1 = load void (...)*, void (...)** %f, align 8
  call void (...) %tmp1()
  ret void
}

define dso_local void @third() {
entry:
  %f = alloca void (...)*, align 8
  %call = call void (...)* @gen()
  store void (...)* %call, void (...)** %f, align 8
  %tmp = load void (...)*, void (...)** %f, align 8
  call void @run(void (...)* %tmp)
  ret void
}