1 ; RUN: llc -mtriple=x86_64-unknown-linux-gnu -verify-machineinstrs < %s | FileCheck %s --check-prefix=ASM
2 ; RUN: llc -mtriple=x86_64-unknown-linux-gnu -verify-machineinstrs -stop-after=finalize-isel < %s | FileCheck %s --check-prefixes=MIR,ISEL
3 ; RUN: llc -mtriple=x86_64-unknown-linux-gnu -verify-machineinstrs -stop-after=kcfi < %s | FileCheck %s --check-prefixes=MIR,KCFI
5 ; ASM: .p2align 4, 0x90
6 ; ASM: .type __cfi_f1,@function
19 ; ASM-NEXT: movl $12345678, %eax
20 ; ASM-LABEL: .Lcfi_func_end0:
21 ; ASM-NEXT: .size __cfi_f1, .Lcfi_func_end0-__cfi_f1
22 define void @f1(ptr noundef %x) !kcfi_type !1 {
25 ; ASM: movl $4282621618, %r10d # imm = 0xFF439EB2
26 ; ASM-NEXT: addl -4(%rdi), %r10d
30 ; ASM-NEXT: .section .kcfi_traps,"ao",@progbits,.text
32 ; ASM-NEXT: .long .Ltmp1-.Ltmp2
35 ; ASM-NEXT: callq *%rdi
39 ; ISEL: CALL64r %0, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, cfi-type 12345678
40 ; KCFI: BUNDLE{{.*}} {
41 ; KCFI-NEXT: KCFI_CHECK $rdi, 12345678, implicit-def $r10, implicit-def $r11, implicit-def $eflags
42 ; KCFI-NEXT: CALL64r killed $rdi, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp
44 call void %x() [ "kcfi"(i32 12345678) ]
49 define void @f2(ptr noundef %x) {
54 ; ISEL: TCRETURNri64 %0, 0, csr_64, implicit $rsp, implicit $ssp, cfi-type 12345678
55 ; KCFI: BUNDLE{{.*}} {
56 ; KCFI-NEXT: KCFI_CHECK $rdi, 12345678, implicit-def $r10, implicit-def $r11, implicit-def $eflags
57 ; KCFI-NEXT: TAILJMPr64 killed $rdi, csr_64, implicit $rsp, implicit $ssp, implicit $rsp, implicit $ssp
59 tail call void %x() [ "kcfi"(i32 12345678) ]
64 define void @f3(ptr noundef %x) #0 {
68 ; ISEL: CALL64pcrel32 &__llvm_retpoline_r11, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, implicit killed $r11, cfi-type 12345678
69 ; KCFI: BUNDLE{{.*}} {
70 ; KCFI-NEXT: KCFI_CHECK $r11, 12345678, implicit-def $r10, implicit-def $r11, implicit-def $eflags
71 ; KCFI-NEXT: CALL64pcrel32 &__llvm_retpoline_r11, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, implicit internal killed $r11
73 call void %x() [ "kcfi"(i32 12345678) ]
78 define void @f4(ptr noundef %x) #0 {
82 ; ISEL: TCRETURNdi64 &__llvm_retpoline_r11, 0, csr_64, implicit $rsp, implicit $ssp, implicit killed $r11, cfi-type 12345678
83 ; KCFI: BUNDLE{{.*}} {
84 ; KCFI-NEXT: KCFI_CHECK $r11, 12345678, implicit-def $r10, implicit-def $r11, implicit-def $eflags
85 ; KCFI-NEXT: TAILJMPd64 &__llvm_retpoline_r11, csr_64, implicit $rsp, implicit $ssp, implicit $rsp, implicit $ssp, implicit internal killed $r11
87 tail call void %x() [ "kcfi"(i32 12345678) ]
91 ;; Ensure we emit Value + 1 for unwanted values (e.g. endbr64 == 4196274163).
92 ; ASM-LABEL: __cfi_f5:
93 ; ASM: movl $4196274164, %eax # imm = 0xFA1E0FF4
94 define void @f5(ptr noundef %x) !kcfi_type !2 {
96 ; ASM: movl $98693132, %r10d # imm = 0x5E1F00C
97 tail call void %x() [ "kcfi"(i32 4196274163) ]
101 ;; Ensure we emit Value + 1 for unwanted values (e.g. -endbr64 == 98693133).
102 ; ASM-LABEL: __cfi_f6:
103 ; ASM: movl $98693134, %eax # imm = 0x5E1F00E
104 define void @f6(ptr noundef %x) !kcfi_type !3 {
106 ; ASM: movl $4196274162, %r10d # imm = 0xFA1E0FF2
107 tail call void %x() [ "kcfi"(i32 98693133) ]
111 @g = external local_unnamed_addr global ptr, align 8
114 ; MIR-LABEL: name: f7
116 ; ISEL: TCRETURNmi64 killed %0, 1, $noreg, 0, $noreg, 0, csr_64, implicit $rsp, implicit $ssp, cfi-type 12345678
117 ; KCFI: $r11 = MOV64rm killed renamable $rax, 1, $noreg, 0, $noreg
118 ; KCFI-NEXT: BUNDLE{{.*}} {
119 ; KCFI-NEXT: KCFI_CHECK $r11, 12345678, implicit-def $r10, implicit-def $r11, implicit-def $eflags
120 ; KCFI-NEXT: TAILJMPr64 internal $r11, csr_64, implicit $rsp, implicit $ssp, implicit $rsp, implicit $ssp
122 %1 = load ptr, ptr @g, align 8
123 tail call void %1() [ "kcfi"(i32 12345678) ]
128 ; MIR-LABEL: name: f8
130 ; ISEL: CALL64m killed %0, 1, $noreg, 0, $noreg, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, cfi-type 12345678
131 ; KCFI: $r11 = MOV64rm killed renamable $rax, 1, $noreg, 0, $noreg
132 ; KCFI-NEXT: BUNDLE{{.*}} {
133 ; KCFI-NEXT: KCFI_CHECK $r11, 12345678, implicit-def $r10, implicit-def $r11, implicit-def $eflags
134 ; KCFI-NEXT: CALL64r internal $r11, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp
136 %1 = load ptr, ptr @g, align 8
137 call void %1() [ "kcfi"(i32 12345678) ]
141 attributes #0 = { "target-features"="+retpoline-indirect-branches,+retpoline-indirect-calls" }
143 !llvm.module.flags = !{!0}
144 !0 = !{i32 4, !"kcfi", i32 1}
146 !2 = !{i32 4196274163}