Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Codegen][X86] Fix /hotpatch with clang-cl and inline asm #87639

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion llvm/lib/Target/X86/X86MCInstLower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,8 +980,10 @@ void X86AsmPrinter::LowerPATCHABLE_OP(const MachineInstr &MI,
SmallString<256> Code;
unsigned MinSize = MI.getOperand(0).getImm();

if (NextMI != MI.getParent()->end()) {
if (NextMI != MI.getParent()->end() && !NextMI->isInlineAsm()) {
// Lower the next MachineInstr to find its byte size.
// If the next instruction is inline assembly, we skip lowering it for now,
// and assume we should always generate NOPs.
MCInst MCI;
MCIL.Lower(&*NextMI, MCI);

Expand Down
17 changes: 17 additions & 0 deletions llvm/test/CodeGen/X86/patchable-prologue.ll
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,20 @@ do.body: ; preds = %do.body, %entry
do.end: ; preds = %do.body
ret void
}


; Test that inline asm is properly hotpatched. We currently don't examine the
; asm instruction when printing it, thus we always emit patching NOPs.

; 64: inline_asm:
aganea marked this conversation as resolved.
Show resolved Hide resolved
; 64-NEXT: # %bb.0:
; 64-NEXT: xchgw %ax, %ax # encoding: [0x66,0x90]
; 64-NEXT: #APP
; 64-NEXT: nop # encoding: [0x90]
; 64-NEXT: #NO_APP

define dso_local void @inline_asm() "patchable-function"="prologue-short-redirect" {
entry:
call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
aganea marked this conversation as resolved.
Show resolved Hide resolved
ret void
}
Loading