Skip to content

Commit 9cec2b2

Browse files
[RegAllocFast] insert additional spills along indirect edges of INLINEASM_BR
When generating spills (stores) for values produced by INLINEASM_BR instructions, make sure to insert one spill per indirect target. Otherwise the reload generated may load from a stack slot that has not yet been stored to (resulting in a load of an uninitialized stack slot). Link: #53562 Fixes: #60855 Reviewed By: MatzeB Differential Revision: https://reviews.llvm.org/D144907
1 parent b8f9ec6 commit 9cec2b2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

llvm/lib/CodeGen/RegAllocFast.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,23 @@ void RegAllocFast::defineVirtReg(MachineInstr &MI, unsigned OpNum,
948948
<< LRI->Reloaded << '\n');
949949
bool Kill = LRI->LastUse == nullptr;
950950
spill(SpillBefore, VirtReg, PhysReg, Kill, LRI->LiveOut);
951+
952+
// We need to place additional spills for each indirect destination of an
953+
// INLINEASM_BR.
954+
if (MI.getOpcode() == TargetOpcode::INLINEASM_BR) {
955+
int FI = StackSlotForVirtReg[VirtReg];
956+
const TargetRegisterClass &RC = *MRI->getRegClass(VirtReg);
957+
for (MachineOperand &MO : MI.operands()) {
958+
if (MO.isMBB()) {
959+
MachineBasicBlock *Succ = MO.getMBB();
960+
TII->storeRegToStackSlot(*Succ, Succ->begin(), PhysReg, Kill,
961+
FI, &RC, TRI, VirtReg);
962+
++NumStores;
963+
Succ->addLiveIn(PhysReg);
964+
}
965+
}
966+
}
967+
951968
LRI->LastUse = nullptr;
952969
}
953970
LRI->LiveOut = false;

llvm/test/CodeGen/X86/callbr-asm-outputs-regallocfast.mir

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ body: |
135135
; CHECK-NEXT: {{ $}}
136136
; CHECK-NEXT: bb.3.label.split (machine-block-address-taken, inlineasm-br-indirect-target):
137137
; CHECK-NEXT: successors: %bb.2(0x80000000)
138+
; CHECK-NEXT: liveins: $eax
138139
; CHECK-NEXT: {{ $}}
139-
; FIXME: this is a load from a stack slot that hasn't been stored to yet!
140+
; CHECK-NEXT: MOV32mr %stack.3, 1, $noreg, 0, $noreg, $eax :: (store (s32) into %stack.3)
140141
; CHECK-NEXT: $eax = MOV32rm %stack.3, 1, $noreg, 0, $noreg :: (load (s32) from %stack.3)
141142
; CHECK-NEXT: MOV32mr %stack.1.x, 1, $noreg, 0, $noreg, killed renamable $eax :: (store (s32) into %ir.x)
142143
; CHECK-NEXT: JMP_1 %bb.2

0 commit comments

Comments
 (0)