diff --git a/llvm/lib/CodeGen/MachineLateInstrsCleanup.cpp b/llvm/lib/CodeGen/MachineLateInstrsCleanup.cpp --- a/llvm/lib/CodeGen/MachineLateInstrsCleanup.cpp +++ b/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; } diff --git a/llvm/test/CodeGen/X86/machine-latecleanup-inlineasm.mir b/llvm/test/CodeGen/X86/machine-latecleanup-inlineasm.mir --- a/llvm/test/CodeGen/X86/machine-latecleanup-inlineasm.mir +++ b/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)