[PATCH] D149191: [CodeGen][MachineLastInstrsCleanup] don't hoist loads above INLINEASM
Nick Desaulniers via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 25 14:09:21 PDT 2023
nickdesaulniers created this revision.
Herald added subscribers: pengfei, hiraditya, kristof.beyls.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
If an inline asm stores to memory or otherwise has side-effects, it's
not safe to hoist loads across it.
This is causing a boot failure on linux-4.19.y branches of the LTS Linux
kernel for ARCH=arm64 with CONFIG_RANDOMIZE_BASE=y (KASLR) and
CONFIG_UNMAP_KERNEL_AT_EL0=y (KPTI).
Fixes: D123394 <https://reviews.llvm.org/D123394>
Link: https://github.com/ClangBuiltLinux/linux/issues/1837
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149191
Files:
llvm/lib/CodeGen/MachineLateInstrsCleanup.cpp
llvm/test/CodeGen/X86/machine-latecleanup-inlineasm.mir
Index: llvm/test/CodeGen/X86/machine-latecleanup-inlineasm.mir
===================================================================
--- llvm/test/CodeGen/X86/machine-latecleanup-inlineasm.mir
+++ llvm/test/CodeGen/X86/machine-latecleanup-inlineasm.mir
@@ -89,8 +89,9 @@
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: $rsp = frame-setup SUB64ri8 $rsp, 24, implicit-def dead $eflags
; CHECK-NEXT: renamable $rax = LOAD_STACK_GUARD :: (dereferenceable invariant load (s64) from @__stack_chk_guard)
- ; CHECK-NEXT: MOV64mr $rsp, 1, $noreg, 16, $noreg, renamable $rax :: (volatile store (s64) into %stack.0.StackGuardSlot)
+ ; CHECK-NEXT: MOV64mr $rsp, 1, $noreg, 16, $noreg, killed renamable $rax :: (volatile store (s64) into %stack.0.StackGuardSlot)
; CHECK-NEXT: INLINEASM &"", 25 /* sideeffect mayload maystore attdialect */
+ ; CHECK-NEXT: renamable $rax = LOAD_STACK_GUARD :: (dereferenceable invariant load (s64) from @__stack_chk_guard)
; CHECK-NEXT: CMP64rm killed renamable $rax, $rsp, 1, $noreg, 16, $noreg, implicit-def $eflags :: (volatile load (s64) from %stack.0.StackGuardSlot)
; CHECK-NEXT: JCC_1 %bb.1, 5, implicit killed $eflags
; CHECK-NEXT: JMP_1 %bb.2
@@ -103,6 +104,7 @@
; CHECK-NEXT: bb.2.entry:
; CHECK-NEXT: $rsp = frame-destroy ADD64ri8 $rsp, 24, implicit-def dead $eflags
; CHECK-NEXT: RET 0
+ ; CHECK-BLANK: {{ $}}
bb.0.entry:
successors: %bb.2(0x7ffff800), %bb.1(0x00000800)
Index: llvm/lib/CodeGen/MachineLateInstrsCleanup.cpp
===================================================================
--- llvm/lib/CodeGen/MachineLateInstrsCleanup.cpp
+++ llvm/lib/CodeGen/MachineLateInstrsCleanup.cpp
@@ -196,9 +196,11 @@
const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
Register FrameReg = TRI->getFrameRegister(*MF);
for (MachineInstr &MI : llvm::make_early_inc_range(*MBB)) {
- // If FrameReg is modified, no previous load-address instructions (using
- // it) are valid.
- if (MI.modifiesRegister(FrameReg, TRI)) {
+ // If FrameReg is modified or we have an inline asm that may store or have
+ // other side effects, no previous load-address instructions (using it) are
+ // valid.
+ if (MI.modifiesRegister(FrameReg, TRI) ||
+ (MI.isInlineAsm() && (MI.hasUnmodeledSideEffects() || MI.mayStore()))) {
MBBDefs.clear();
continue;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149191.516902.patch
Type: text/x-patch
Size: 2386 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230425/81ce8e5b/attachment.bin>
More information about the llvm-commits
mailing list