xref: /aosp_15_r20/external/llvm/test/Transforms/Inline/devirtualize-3.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt -basicaa -inline -S -sroa -gvn -instcombine < %s | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker; PR5009
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Worker; CHECK: define i32 @main()
5*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: entry:
6*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  call void @exit(i32 38)
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Workertarget 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"
9*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-apple-darwin10.0.0"
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker%struct.cont_t = type { void (i8*, i32)*, i8* }
12*9880d681SAndroid Build Coastguard Worker%struct.foo_sf_t = type { %struct.cont_t*, i32 }
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Workerdefine i32 @main() nounwind ssp {
15*9880d681SAndroid Build Coastguard Workerentry:
16*9880d681SAndroid Build Coastguard Worker  %cont = alloca %struct.cont_t, align 8          ; <%struct.cont_t*> [#uses=4]
17*9880d681SAndroid Build Coastguard Worker  %tmp = getelementptr inbounds %struct.cont_t, %struct.cont_t* %cont, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=1]
18*9880d681SAndroid Build Coastguard Worker  %tmp1 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %cont, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=2]
19*9880d681SAndroid Build Coastguard Worker  store void (i8*, i32)* bitcast (void (%struct.cont_t*, i32)* @quit to void (i8*, i32)*), void (i8*, i32)** %tmp1
20*9880d681SAndroid Build Coastguard Worker  %tmp2 = load void (i8*, i32)*, void (i8*, i32)** %tmp1            ; <void (i8*, i32)*> [#uses=1]
21*9880d681SAndroid Build Coastguard Worker  store void (i8*, i32)* %tmp2, void (i8*, i32)** %tmp
22*9880d681SAndroid Build Coastguard Worker  %tmp3 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %cont, i32 0, i32 1 ; <i8**> [#uses=1]
23*9880d681SAndroid Build Coastguard Worker  store i8* null, i8** %tmp3
24*9880d681SAndroid Build Coastguard Worker  call void @foo(%struct.cont_t* %cont)
25*9880d681SAndroid Build Coastguard Worker  ret i32 0
26*9880d681SAndroid Build Coastguard Worker}
27*9880d681SAndroid Build Coastguard Worker
28*9880d681SAndroid Build Coastguard Workerdefine internal void @quit(%struct.cont_t* %cont, i32 %rcode) nounwind ssp {
29*9880d681SAndroid Build Coastguard Workerentry:
30*9880d681SAndroid Build Coastguard Worker  call void @exit(i32 %rcode) noreturn
31*9880d681SAndroid Build Coastguard Worker  unreachable
32*9880d681SAndroid Build Coastguard Worker}
33*9880d681SAndroid Build Coastguard Worker
34*9880d681SAndroid Build Coastguard Workerdefine internal void @foo(%struct.cont_t* %c) nounwind ssp {
35*9880d681SAndroid Build Coastguard Workerentry:
36*9880d681SAndroid Build Coastguard Worker  %sf = alloca %struct.foo_sf_t, align 8          ; <%struct.foo_sf_t*> [#uses=3]
37*9880d681SAndroid Build Coastguard Worker  %next = alloca %struct.cont_t, align 8          ; <%struct.cont_t*> [#uses=3]
38*9880d681SAndroid Build Coastguard Worker  %tmp = getelementptr inbounds %struct.foo_sf_t, %struct.foo_sf_t* %sf, i32 0, i32 0 ; <%struct.cont_t**> [#uses=1]
39*9880d681SAndroid Build Coastguard Worker  store %struct.cont_t* %c, %struct.cont_t** %tmp
40*9880d681SAndroid Build Coastguard Worker  %tmp2 = getelementptr inbounds %struct.foo_sf_t, %struct.foo_sf_t* %sf, i32 0, i32 1 ; <i32*> [#uses=1]
41*9880d681SAndroid Build Coastguard Worker  store i32 2, i32* %tmp2
42*9880d681SAndroid Build Coastguard Worker  %tmp4 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %next, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=1]
43*9880d681SAndroid Build Coastguard Worker  store void (i8*, i32)* bitcast (void (%struct.foo_sf_t*, i32)* @foo2 to void (i8*, i32)*), void (i8*, i32)** %tmp4
44*9880d681SAndroid Build Coastguard Worker  %tmp5 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %next, i32 0, i32 1 ; <i8**> [#uses=1]
45*9880d681SAndroid Build Coastguard Worker  %conv = bitcast %struct.foo_sf_t* %sf to i8*    ; <i8*> [#uses=1]
46*9880d681SAndroid Build Coastguard Worker  store i8* %conv, i8** %tmp5
47*9880d681SAndroid Build Coastguard Worker  call void @bar(%struct.cont_t* %next, i32 14)
48*9880d681SAndroid Build Coastguard Worker  ret void
49*9880d681SAndroid Build Coastguard Worker}
50*9880d681SAndroid Build Coastguard Worker
51*9880d681SAndroid Build Coastguard Workerdefine internal void @foo2(%struct.foo_sf_t* %sf, i32 %y) nounwind ssp {
52*9880d681SAndroid Build Coastguard Workerentry:
53*9880d681SAndroid Build Coastguard Worker  %tmp1 = getelementptr inbounds %struct.foo_sf_t, %struct.foo_sf_t* %sf, i32 0, i32 0 ; <%struct.cont_t**> [#uses=1]
54*9880d681SAndroid Build Coastguard Worker  %tmp2 = load %struct.cont_t*, %struct.cont_t** %tmp1             ; <%struct.cont_t*> [#uses=1]
55*9880d681SAndroid Build Coastguard Worker  %tmp3 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %tmp2, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=1]
56*9880d681SAndroid Build Coastguard Worker  %tmp4 = load void (i8*, i32)*, void (i8*, i32)** %tmp3            ; <void (i8*, i32)*> [#uses=1]
57*9880d681SAndroid Build Coastguard Worker  %tmp6 = getelementptr inbounds %struct.foo_sf_t, %struct.foo_sf_t* %sf, i32 0, i32 0 ; <%struct.cont_t**> [#uses=1]
58*9880d681SAndroid Build Coastguard Worker  %tmp7 = load %struct.cont_t*, %struct.cont_t** %tmp6             ; <%struct.cont_t*> [#uses=1]
59*9880d681SAndroid Build Coastguard Worker  %conv = bitcast %struct.cont_t* %tmp7 to i8*    ; <i8*> [#uses=1]
60*9880d681SAndroid Build Coastguard Worker  %tmp9 = getelementptr inbounds %struct.foo_sf_t, %struct.foo_sf_t* %sf, i32 0, i32 1 ; <i32*> [#uses=1]
61*9880d681SAndroid Build Coastguard Worker  %tmp10 = load i32, i32* %tmp9                        ; <i32> [#uses=1]
62*9880d681SAndroid Build Coastguard Worker  %mul = mul i32 %tmp10, %y                       ; <i32> [#uses=1]
63*9880d681SAndroid Build Coastguard Worker  call void %tmp4(i8* %conv, i32 %mul)
64*9880d681SAndroid Build Coastguard Worker  ret void
65*9880d681SAndroid Build Coastguard Worker}
66*9880d681SAndroid Build Coastguard Worker
67*9880d681SAndroid Build Coastguard Workerdefine internal void @bar(%struct.cont_t* %c, i32 %y) nounwind ssp {
68*9880d681SAndroid Build Coastguard Workerentry:
69*9880d681SAndroid Build Coastguard Worker  %tmp1 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %c, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=1]
70*9880d681SAndroid Build Coastguard Worker  %tmp2 = load void (i8*, i32)*, void (i8*, i32)** %tmp1            ; <void (i8*, i32)*> [#uses=1]
71*9880d681SAndroid Build Coastguard Worker  %tmp4 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %c, i32 0, i32 1 ; <i8**> [#uses=1]
72*9880d681SAndroid Build Coastguard Worker  %tmp5 = load i8*, i8** %tmp4                         ; <i8*> [#uses=1]
73*9880d681SAndroid Build Coastguard Worker  %add = add nsw i32 %y, 5                        ; <i32> [#uses=1]
74*9880d681SAndroid Build Coastguard Worker  call void %tmp2(i8* %tmp5, i32 %add)
75*9880d681SAndroid Build Coastguard Worker  ret void
76*9880d681SAndroid Build Coastguard Worker}
77*9880d681SAndroid Build Coastguard Worker
78*9880d681SAndroid Build Coastguard Workerdeclare void @exit(i32) noreturn
79*9880d681SAndroid Build Coastguard Worker
80