Bump version to 19.1.0-rc3
[llvm-project.git] / llvm / test / CodeGen / X86 / retpoline-external.ll
blob8c068bb474782c0747334475b297171b790c04d4
1 ; RUN: llc -verify-machineinstrs -mtriple=x86_64-unknown < %s | FileCheck %s --implicit-check-not="jmp.*\*" --implicit-check-not="call.*\*" --check-prefix=X64
2 ; RUN: llc -verify-machineinstrs -mtriple=x86_64-unknown -O0 < %s | FileCheck %s --implicit-check-not="jmp.*\*" --implicit-check-not="call.*\*" --check-prefix=X64FAST
4 ; RUN: llc -verify-machineinstrs -mtriple=i686-unknown < %s | FileCheck %s --implicit-check-not="jmp.*\*" --implicit-check-not="call.*\*" --check-prefix=X86
5 ; RUN: llc -verify-machineinstrs -mtriple=i686-unknown -O0 < %s | FileCheck %s --implicit-check-not="jmp.*\*" --implicit-check-not="call.*\*" --check-prefix=X86FAST
7 declare dso_local void @bar(i32)
9 ; Test a simple indirect call and tail call.
10 define void @icall_reg(ptr %fp, i32 %x) #0 {
11 entry:
12   tail call void @bar(i32 %x)
13   tail call void %fp(i32 %x)
14   tail call void @bar(i32 %x)
15   tail call void %fp(i32 %x)
16   ret void
19 ; X64-LABEL: icall_reg:
20 ; X64-DAG:   movq %rdi, %[[fp:[^ ]*]]
21 ; X64-DAG:   movl %esi, %[[x:[^ ]*]]
22 ; X64:       movl %esi, %edi
23 ; X64:       callq bar
24 ; X64-DAG:   movl %[[x]], %edi
25 ; X64-DAG:   movq %[[fp]], %r11
26 ; X64:       callq __x86_indirect_thunk_r11
27 ; X64:       movl %[[x]], %edi
28 ; X64:       callq bar
29 ; X64-DAG:   movl %[[x]], %edi
30 ; X64-DAG:   movq %[[fp]], %r11
31 ; X64:       jmp __x86_indirect_thunk_r11 # TAILCALL
33 ; X64FAST-LABEL: icall_reg:
34 ; X64FAST:       callq bar
35 ; X64FAST:       callq __x86_indirect_thunk_r11
36 ; X64FAST:       callq bar
37 ; X64FAST:       jmp __x86_indirect_thunk_r11 # TAILCALL
39 ; X86-LABEL: icall_reg:
40 ; X86-DAG:   movl 12(%esp), %[[fp:[^ ]*]]
41 ; X86-DAG:   movl 16(%esp), %[[x:[^ ]*]]
42 ; X86:       pushl %[[x]]
43 ; X86:       calll bar
44 ; X86:       movl %[[fp]], %eax
45 ; X86:       pushl %[[x]]
46 ; X86:       calll __x86_indirect_thunk_eax
47 ; X86:       pushl %[[x]]
48 ; X86:       calll bar
49 ; X86:       movl %[[fp]], %eax
50 ; X86:       pushl %[[x]]
51 ; X86:       calll __x86_indirect_thunk_eax
52 ; X86-NOT:   # TAILCALL
54 ; X86FAST-LABEL: icall_reg:
55 ; X86FAST:       calll bar
56 ; X86FAST:       calll __x86_indirect_thunk_eax
57 ; X86FAST:       calll bar
58 ; X86FAST:       calll __x86_indirect_thunk_eax
61 @global_fp = external dso_local global ptr
63 ; Test an indirect call through a global variable.
64 define void @icall_global_fp(i32 %x, ptr %fpp) #0 {
65   %fp1 = load ptr, ptr @global_fp
66   call void %fp1(i32 %x)
67   %fp2 = load ptr, ptr @global_fp
68   tail call void %fp2(i32 %x)
69   ret void
72 ; X64-LABEL: icall_global_fp:
73 ; X64-DAG:   movl %edi, %[[x:[^ ]*]]
74 ; X64-DAG:   movq global_fp(%rip), %r11
75 ; X64:       callq __x86_indirect_thunk_r11
76 ; X64-DAG:   movl %[[x]], %edi
77 ; X64-DAG:   movq global_fp(%rip), %r11
78 ; X64:       jmp __x86_indirect_thunk_r11 # TAILCALL
80 ; X64FAST-LABEL: icall_global_fp:
81 ; X64FAST:       movq global_fp(%rip), %r11
82 ; X64FAST:       callq __x86_indirect_thunk_r11
83 ; X64FAST:       movq global_fp(%rip), %r11
84 ; X64FAST:       jmp __x86_indirect_thunk_r11 # TAILCALL
86 ; X86-LABEL: icall_global_fp:
87 ; X86:       movl global_fp, %eax
88 ; X86:       pushl 4(%esp)
89 ; X86:       calll __x86_indirect_thunk_eax
90 ; X86:       addl $4, %esp
91 ; X86:       movl global_fp, %eax
92 ; X86:       jmp __x86_indirect_thunk_eax # TAILCALL
94 ; X86FAST-LABEL: icall_global_fp:
95 ; X86FAST:       calll __x86_indirect_thunk_eax
96 ; X86FAST:       jmp __x86_indirect_thunk_eax # TAILCALL
99 %struct.Foo = type { ptr }
101 ; Test an indirect call through a vtable.
102 define void @vcall(ptr %obj) #0 {
103   %vptr = load ptr, ptr %obj
104   %vslot = getelementptr ptr, ptr %vptr, i32 1
105   %fp = load ptr, ptr %vslot
106   tail call void %fp(ptr %obj)
107   tail call void %fp(ptr %obj)
108   ret void
111 ; X64-LABEL: vcall:
112 ; X64:       movq %rdi, %[[obj:[^ ]*]]
113 ; X64:       movq (%rdi), %[[vptr:[^ ]*]]
114 ; X64:       movq 8(%[[vptr]]), %[[fp:[^ ]*]]
115 ; X64:       movq %[[fp]], %r11
116 ; X64:       callq __x86_indirect_thunk_r11
117 ; X64-DAG:   movq %[[obj]], %rdi
118 ; X64-DAG:   movq %[[fp]], %r11
119 ; X64:       jmp __x86_indirect_thunk_r11 # TAILCALL
121 ; X64FAST-LABEL: vcall:
122 ; X64FAST:       callq __x86_indirect_thunk_r11
123 ; X64FAST:       jmp __x86_indirect_thunk_r11 # TAILCALL
125 ; X86-LABEL: vcall:
126 ; X86:       movl 8(%esp), %[[obj:[^ ]*]]
127 ; X86:       movl (%[[obj]]), %[[vptr:[^ ]*]]
128 ; X86:       movl 4(%[[vptr]]), %[[fp:[^ ]*]]
129 ; X86:       movl %[[fp]], %eax
130 ; X86:       pushl %[[obj]]
131 ; X86:       calll __x86_indirect_thunk_eax
132 ; X86:       addl $4, %esp
133 ; X86:       movl %[[fp]], %eax
134 ; X86:       jmp __x86_indirect_thunk_eax # TAILCALL
136 ; X86FAST-LABEL: vcall:
137 ; X86FAST:       calll __x86_indirect_thunk_eax
138 ; X86FAST:       jmp __x86_indirect_thunk_eax # TAILCALL
141 declare dso_local void @direct_callee()
143 define void @direct_tail() #0 {
144   tail call void @direct_callee()
145   ret void
148 ; X64-LABEL: direct_tail:
149 ; X64:       jmp direct_callee # TAILCALL
150 ; X64FAST-LABEL: direct_tail:
151 ; X64FAST:   jmp direct_callee # TAILCALL
152 ; X86-LABEL: direct_tail:
153 ; X86:       jmp direct_callee # TAILCALL
154 ; X86FAST-LABEL: direct_tail:
155 ; X86FAST:   jmp direct_callee # TAILCALL
158 ; Lastly check that no thunks were emitted.
159 ; X64-NOT: __{{.*}}_retpoline_{{.*}}:
160 ; X64FAST-NOT: __{{.*}}_retpoline_{{.*}}:
161 ; X86-NOT: __{{.*}}_retpoline_{{.*}}:
162 ; X86FAST-NOT: __{{.*}}_retpoline_{{.*}}:
165 attributes #0 = { "target-features"="+retpoline-indirect-calls,+retpoline-external-thunk" }