Skip to content

Commit e861196

Browse files
nickdesaulnierststellar
authored andcommitted
[CodeGen][MachineLastInstrsCleanup] fix INLINEASM_BR hazard
If the removable definition resides in an INLINEASM_BR target, the reuseable candidate might not dominate the INLINEASM_BR. bb0: INLINEASM_BR &"" %bb.1 renamable $x8 = MOVi64imm 29273397577910035 B %bb.2 ... bb1: renamable $x8 = MOVi64imm 29273397577910035 renamable $x8 = ADDXri killed renamable $x8, 2048, 0 bb2: Removing the second mov is a hazard when the inline asm branches to bb1. Skip such replacements when the to be removed instruction is in the target of such an INLINEASM_BR instruction. We could get more aggressive about this in the future, but for now simply abort. 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). Link: https://reviews.llvm.org/D123394 Link: ClangBuiltLinux/linux#1837 Thanks to @nathanchance for the report, and @ARDB for debugging. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D149191 (cherry picked from commit 012ea74)
1 parent ec79a47 commit e861196

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

llvm/lib/CodeGen/MachineLateInstrsCleanup.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ bool MachineLateInstrsCleanup::processBlock(MachineBasicBlock *MBB) {
175175
Reg2DefMap &MBBDefs = RegDefs[MBB->getNumber()];
176176

177177
// Find reusable definitions in the predecessor(s).
178-
if (!MBB->pred_empty() && !MBB->isEHPad()) {
178+
if (!MBB->pred_empty() && !MBB->isEHPad() &&
179+
!MBB->isInlineAsmBrIndirectTarget()) {
179180
MachineBasicBlock *FirstPred = *MBB->pred_begin();
180181
for (auto [Reg, DefMI] : RegDefs[FirstPred->getNumber()])
181182
if (llvm::all_of(

llvm/test/CodeGen/AArch64/machine-latecleanup-inlineasm.mir

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ body: |
159159
; CHECK-NEXT: {{ $}}
160160
; CHECK-NEXT: bb.1.bb8 (machine-block-address-taken, inlineasm-br-indirect-target):
161161
; CHECK-NEXT: successors: %bb.2(0x80000000)
162-
; CHECK-NEXT: liveins: $w20, $x19, $x21, $x22, $x23, $x24, $x8
162+
; CHECK-NEXT: liveins: $w20, $x19, $x21, $x22, $x23, $x24
163163
; CHECK-NEXT: {{ $}}
164+
; CHECK-NEXT: renamable $x8 = MOVi64imm 29273397577910035
164165
; CHECK-NEXT: renamable $x8 = ADDXri killed renamable $x8, 2048, 0
165166
; CHECK-NEXT: {{ $}}
166167
; CHECK-NEXT: bb.2.bb9:

0 commit comments

Comments
 (0)