[llvm-branch-commits] [llvm] release/18.x: [Codegen][X86] Fix /HOTPATCH with clang-cl and inline asm (#87639) (PR #88388)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Apr 11 06:01:19 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-x86
Author: None (llvmbot)
<details>
<summary>Changes</summary>
Backport ec1af63dde58c735fe60d6f2aafdb10fa93f410d
Requested by: @<!-- -->aganea
---
Full diff: https://github.com/llvm/llvm-project/pull/88388.diff
2 Files Affected:
- (modified) llvm/lib/Target/X86/X86MCInstLower.cpp (+3-1)
- (modified) llvm/test/CodeGen/X86/patchable-prologue.ll (+17)
``````````diff
diff --git a/llvm/lib/Target/X86/X86MCInstLower.cpp b/llvm/lib/Target/X86/X86MCInstLower.cpp
index 58ebe023cd61ec..7ce0aa22b99795 100644
--- a/llvm/lib/Target/X86/X86MCInstLower.cpp
+++ b/llvm/lib/Target/X86/X86MCInstLower.cpp
@@ -959,8 +959,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);
diff --git a/llvm/test/CodeGen/X86/patchable-prologue.ll b/llvm/test/CodeGen/X86/patchable-prologue.ll
index 71a392845fdea3..43761e3d1e1eb9 100644
--- a/llvm/test/CodeGen/X86/patchable-prologue.ll
+++ b/llvm/test/CodeGen/X86/patchable-prologue.ll
@@ -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:
+; 64-NEXT: # %bb.0:
+; 64-NEXT: xchgw %ax, %ax # encoding: [0x66,0x90]
+; 64-NEXT: #APP
+; 64-NEXT: int3 # encoding: [0xcc]
+; 64-NEXT: #NO_APP
+
+define dso_local void @inline_asm() "patchable-function"="prologue-short-redirect" {
+entry:
+ call void asm sideeffect "int3", "~{dirflag},~{fpsr},~{flags}"()
+ ret void
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/88388
More information about the llvm-branch-commits
mailing list