xref: /llvm-project/llvm/test/Transforms/Inline/devirtualize-3.ll (revision 1228becf7df28c68579f2b9b390b74aa41149a0a)
1; RUN: opt -aa-pipeline=basic-aa -S -passes='default<O2>' < %s | FileCheck %s
2; PR5009
3
4; CHECK: define noundef i32 @main()
5; CHECK-NEXT: entry:
6; CHECK-NEXT:  call void @exit(i32 38)
7
8target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
9target triple = "x86_64-apple-darwin10.0.0"
10
11%struct.cont_t = type { ptr, ptr }
12%struct.foo_sf_t = type { ptr, i32 }
13
14define i32 @main() nounwind ssp {
15entry:
16  %cont = alloca %struct.cont_t, align 8          ; <ptr> [#uses=4]
17  %tmp = getelementptr inbounds %struct.cont_t, ptr %cont, i32 0, i32 0 ; <ptr> [#uses=1]
18  %tmp1 = getelementptr inbounds %struct.cont_t, ptr %cont, i32 0, i32 0 ; <ptr> [#uses=2]
19  store ptr @quit, ptr %tmp1
20  %tmp2 = load ptr, ptr %tmp1            ; <ptr> [#uses=1]
21  store ptr %tmp2, ptr %tmp
22  %tmp3 = getelementptr inbounds %struct.cont_t, ptr %cont, i32 0, i32 1 ; <ptr> [#uses=1]
23  store ptr null, ptr %tmp3
24  call void @foo(ptr %cont)
25  ret i32 0
26}
27
28define internal void @quit(ptr %cont, i32 %rcode) nounwind ssp {
29entry:
30  call void @exit(i32 %rcode) noreturn
31  unreachable
32}
33
34define internal void @foo(ptr %c) nounwind ssp {
35entry:
36  %sf = alloca %struct.foo_sf_t, align 8          ; <ptr> [#uses=3]
37  %next = alloca %struct.cont_t, align 8          ; <ptr> [#uses=3]
38  %tmp = getelementptr inbounds %struct.foo_sf_t, ptr %sf, i32 0, i32 0 ; <ptr> [#uses=1]
39  store ptr %c, ptr %tmp
40  %tmp2 = getelementptr inbounds %struct.foo_sf_t, ptr %sf, i32 0, i32 1 ; <ptr> [#uses=1]
41  store i32 2, ptr %tmp2
42  %tmp4 = getelementptr inbounds %struct.cont_t, ptr %next, i32 0, i32 0 ; <ptr> [#uses=1]
43  store ptr @foo2, ptr %tmp4
44  %tmp5 = getelementptr inbounds %struct.cont_t, ptr %next, i32 0, i32 1 ; <ptr> [#uses=1]
45  store ptr %sf, ptr %tmp5
46  call void @bar(ptr %next, i32 14)
47  ret void
48}
49
50define internal void @foo2(ptr %sf, i32 %y) nounwind ssp {
51entry:
52  %tmp1 = getelementptr inbounds %struct.foo_sf_t, ptr %sf, i32 0, i32 0 ; <ptr> [#uses=1]
53  %tmp2 = load ptr, ptr %tmp1             ; <ptr> [#uses=1]
54  %tmp3 = getelementptr inbounds %struct.cont_t, ptr %tmp2, i32 0, i32 0 ; <ptr> [#uses=1]
55  %tmp4 = load ptr, ptr %tmp3            ; <ptr> [#uses=1]
56  %tmp6 = getelementptr inbounds %struct.foo_sf_t, ptr %sf, i32 0, i32 0 ; <ptr> [#uses=1]
57  %tmp7 = load ptr, ptr %tmp6             ; <ptr> [#uses=1]
58  %tmp9 = getelementptr inbounds %struct.foo_sf_t, ptr %sf, i32 0, i32 1 ; <ptr> [#uses=1]
59  %tmp10 = load i32, ptr %tmp9                        ; <i32> [#uses=1]
60  %mul = mul i32 %tmp10, %y                       ; <i32> [#uses=1]
61  call void %tmp4(ptr %tmp7, i32 %mul)
62  ret void
63}
64
65define internal void @bar(ptr %c, i32 %y) nounwind ssp {
66entry:
67  %tmp1 = getelementptr inbounds %struct.cont_t, ptr %c, i32 0, i32 0 ; <ptr> [#uses=1]
68  %tmp2 = load ptr, ptr %tmp1            ; <ptr> [#uses=1]
69  %tmp4 = getelementptr inbounds %struct.cont_t, ptr %c, i32 0, i32 1 ; <ptr> [#uses=1]
70  %tmp5 = load ptr, ptr %tmp4                         ; <ptr> [#uses=1]
71  %add = add nsw i32 %y, 5                        ; <i32> [#uses=1]
72  call void %tmp2(ptr %tmp5, i32 %add)
73  ret void
74}
75
76declare void @exit(i32) noreturn
77
78