Skip to content

Commit dba3d6e

Browse files
!fixup address reviews
1 parent d364a33 commit dba3d6e

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

llvm/lib/CodeGen/RegAllocFast.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ class RegAllocFastImpl {
391391
bool mayLiveOut(Register VirtReg);
392392
bool mayLiveIn(Register VirtReg);
393393

394-
bool isInlineAsmBrSpill(const MachineInstr &MI) const;
394+
bool mayBeSpillFromInlineAsmBr(const MachineInstr &MI) const;
395395

396396
void dumpState() const;
397397
};
@@ -493,17 +493,18 @@ static bool dominates(InstrPosIndexes &PosIndexes, const MachineInstr &A,
493493
return IndexA < IndexB;
494494
}
495495

496-
bool RegAllocFastImpl::isInlineAsmBrSpill(const MachineInstr &MI) const {
496+
/// Returns true if \p MI is a spill of a live-in physical register in a block
497+
/// targeted by an INLINEASM_BR. Such spills must precede reloads of live-in
498+
/// virtual registers, so that we do not reload from an uninitialized stack
499+
/// slot.
500+
bool RegAllocFastImpl::mayBeSpillFromInlineAsmBr(const MachineInstr &MI) const {
497501
int FI;
498502
auto *MBB = MI.getParent();
499503
if (MBB->isInlineAsmBrIndirectTarget() && TII->isStoreToStackSlot(MI, FI) &&
500-
MFI->isSpillSlotObjectIndex(FI)) {
504+
MFI->isSpillSlotObjectIndex(FI))
501505
for (const auto &Op : MI.operands())
502-
if (Op.isReg() && any_of(MBB->liveins(), [&](const auto &RegP) {
503-
return Op.getReg() == RegP.PhysReg;
504-
}))
506+
if (Op.isReg() && MBB->isLiveIn(Op.getReg()))
505507
return true;
506-
}
507508
return false;
508509
}
509510

@@ -665,7 +666,7 @@ MachineBasicBlock::iterator RegAllocFastImpl::getMBBBeginInsertionPoint(
665666
}
666667

667668
// Skip prologues and inlineasm_br spills to place reloads afterwards.
668-
if (!TII->isBasicBlockPrologue(*I) && !isInlineAsmBrSpill(*I))
669+
if (!TII->isBasicBlockPrologue(*I) && !mayBeSpillFromInlineAsmBr(*I))
669670
break;
670671

671672
// However if a prolog instruction reads a register that needs to be
@@ -752,7 +753,7 @@ bool RegAllocFastImpl::displacePhysReg(MachineInstr &MI, MCRegister PhysReg) {
752753
assert(LRI != LiveVirtRegs.end() && "datastructures in sync");
753754
MachineBasicBlock::iterator ReloadBefore =
754755
std::next((MachineBasicBlock::iterator)MI.getIterator());
755-
while (isInlineAsmBrSpill(*ReloadBefore))
756+
while (mayBeSpillFromInlineAsmBr(*ReloadBefore))
756757
++ReloadBefore;
757758
reload(ReloadBefore, VirtReg, LRI->PhysReg);
758759

llvm/test/CodeGen/X86/regallocfast-callbr-asm-spills-after-reload.mir

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ body: |
5454
bb.3 (machine-block-address-taken, inlineasm-br-indirect-target):
5555
successors: %bb.2(0x80000000)
5656
57-
; FIXME: This is a miscompilation, as, despite spilling the value modified by the inlineasm_br,
58-
; the reload emitted still reads from an uninitialized stack slot.
5957
; CHECK: MOV32mr %stack.2, 1, $noreg, 0, $noreg, $eax :: (store (s32) into %stack.2)
6058
; CHECK-NEXT: $ecx = MOV32rm %stack.2, 1, $noreg, 0, $noreg :: (load (s32) from %stack.2)
6159
; CHECK-NEXT: $rax = MOV64rm %stack.3, 1, $noreg, 0, $noreg :: (load (s64) from %stack.3)

0 commit comments

Comments
 (0)