1 ; RUN: llc -verify-machineinstrs -filetype=obj -o - -mtriple=x86_64-apple-macosx < %s | llvm-objdump --no-print-imm-hex --triple=x86_64-apple-macosx -d - | FileCheck %s
2 ; RUN: llc -verify-machineinstrs -mtriple=x86_64-apple-macosx < %s | FileCheck %s --check-prefix=CHECK-ALIGN
3 ; RUN: llc -verify-machineinstrs -show-mc-encoding -mtriple=i386 < %s | FileCheck %s --check-prefixes=32,32CFI,XCHG
4 ; RUN: llc -verify-machineinstrs -show-mc-encoding -mtriple=i386-windows-msvc < %s | FileCheck %s --check-prefixes=32,MOV
5 ; RUN: llc -verify-machineinstrs -show-mc-encoding -mtriple=i386-windows-msvc -mcpu=pentium3 < %s | FileCheck %s --check-prefixes=32,MOV
6 ; RUN: llc -verify-machineinstrs -show-mc-encoding -mtriple=i386-windows-msvc -mcpu=pentium4 < %s | FileCheck %s --check-prefixes=32,XCHG
7 ; RUN: llc -verify-machineinstrs -show-mc-encoding -mtriple=x86_64-windows-msvc < %s | FileCheck %s --check-prefix=64
9 declare void @callee(ptr)
11 define void @f0() "patchable-function"="prologue-short-redirect" {
12 ; CHECK-LABEL: _f0{{>?}}:
13 ; CHECK-NEXT: 66 90 nop
15 ; CHECK-ALIGN: .p2align 4, 0x90
19 ; 32CFI-NEXT: .cfi_startproc
21 ; XCHG-NEXT: xchgw %ax, %ax # encoding: [0x66,0x90]
22 ; MOV-NEXT: movl %edi, %edi # encoding: [0x8b,0xff]
27 ; 64-NEXT: xchgw %ax, %ax # encoding: [0x66,0x90]
33 define void @f1() "patchable-function"="prologue-short-redirect" "frame-pointer"="all" {
35 ; CHECK-NEXT: ff f5 pushq %rbp
37 ; CHECK-ALIGN: .p2align 4, 0x90
41 ; 32CFI-NEXT: .cfi_startproc
43 ; XCHG-NEXT: xchgw %ax, %ax # encoding: [0x66,0x90]
44 ; MOV-NEXT: movl %edi, %edi # encoding: [0x8b,0xff]
48 ; 64-NEXT: .seh_proc f1
55 define void @f2() "patchable-function"="prologue-short-redirect" {
57 ; CHECK-NEXT: 48 81 ec a8 00 00 00 subq $168, %rsp
59 ; CHECK-ALIGN: .p2align 4, 0x90
63 ; 32CFI-NEXT: .cfi_startproc
65 ; XCHG-NEXT: xchgw %ax, %ax # encoding: [0x66,0x90]
66 ; MOV-NEXT: movl %edi, %edi # encoding: [0x8b,0xff]
70 ; 64-NEXT: .seh_proc f2
72 ; 64-NEXT: subq $200, %rsp
74 %ptr = alloca i64, i32 20
75 call void @callee(ptr %ptr)
79 define void @f3() "patchable-function"="prologue-short-redirect" optsize {
81 ; CHECK-NEXT: 66 90 nop
83 ; CHECK-ALIGN: .p2align 4, 0x90
87 ; 32CFI-NEXT: .cfi_startproc
89 ; XCHG-NEXT: xchgw %ax, %ax
90 ; MOV-NEXT: movl %edi, %edi
95 ; 64-NEXT: xchgw %ax, %ax
101 ; This testcase happens to produce a KILL instruction at the beginning of the
102 ; first basic block. In this case the 2nd instruction should be turned into a
104 ; CHECK-LABEL: f4{{>?}}:
105 ; CHECK-NEXT: 8b 0c 37 movl (%rdi,%rsi), %ecx
107 ; 32CFI-NEXT: .cfi_startproc
109 ; XCHG-NEXT: xchgw %ax, %ax
110 ; MOV-NEXT: movl %edi, %edi
111 ; 32-NEXT: pushl %ebx
115 ; 64-NOT: xchgw %ax, %ax
117 define i32 @f4(ptr %arg1, i64 %arg2, i32 %arg3) "patchable-function"="prologue-short-redirect" {
119 %tmp10 = getelementptr i8, ptr %arg1, i64 %arg2
120 %tmp12 = load i32, ptr %tmp10, align 4
122 %tmp13 = add i32 %tmp12, %arg3
123 %tmp14 = cmpxchg ptr %tmp10, i32 %tmp12, i32 %tmp13 seq_cst monotonic
124 %tmp15 = extractvalue { i32, i1 } %tmp14, 1
125 br i1 %tmp15, label %bb21, label %bb16
131 %tmp22 = phi i32 [ %tmp12, %bb ], [ %arg3, %bb16 ]
135 ; This testcase produces an empty function (not even a ret on some targets).
136 ; This scenario can happen with undefined behavior.
137 ; Ensure that the "patchable-function" pass supports this case.
138 ; CHECK-LABEL: _emptyfunc
139 ; CHECK-NEXT: 0f 0b ud2
141 ; CHECK-ALIGN: .p2align 4, 0x90
142 ; CHECK-ALIGN: _emptyfunc:
145 ; 32CFI-NEXT: .cfi_startproc
147 ; XCHG-NEXT: xchgw %ax, %ax
148 ; MOV-NEXT: movl %edi, %edi
152 ; 64-NEXT: xchgw %ax, %ax
154 ; From code: int emptyfunc() {}
155 define i32 @emptyfunc() "patchable-function"="prologue-short-redirect" {
160 ; Hotpatch feature must ensure no jump within the function goes to the first instruction.
162 ; void jmp_to_start(char *b) {
164 ; } while ((++(*b++)));
167 ; CHECK-ALIGN: .p2align 4, 0x90
168 ; CHECK-ALIGN: _jmp_to_start:
171 ; 32CFI-NEXT: .cfi_startproc
173 ; XCHG-NEXT: xchgw %ax, %ax
174 ; MOV-NEXT: movl %edi, %edi
178 ; 64-NEXT: xchgw %ax, %ax
180 define dso_local void @jmp_to_start(ptr inreg nocapture noundef %b) "patchable-function"="prologue-short-redirect" {
183 do.body: ; preds = %do.body, %entry
184 %b.addr.0 = phi ptr [ %b, %entry ], [ %incdec.ptr, %do.body ]
185 %incdec.ptr = getelementptr inbounds i8, ptr %b.addr.0, i64 1
186 %0 = load i8, ptr %b.addr.0, align 1
188 store i8 %inc, ptr %b.addr.0, align 1
189 %tobool.not = icmp eq i8 %inc, 0
190 br i1 %tobool.not, label %do.end, label %do.body
191 do.end: ; preds = %do.body