Files
llvm-project/llvm/lib/Target/AMDGPU/SISpillUtils.cpp
Sergio Afonso 2cff995e91 [AMDGPU] Fix crash with dead frame indices in debug values (#183297)
When spill slots are eliminated (VGPR-to-AGPR, SGPR-to-VGPR lanes),
debug values referencing these frame indices were not always properly
cleaned up. This caused an assertion failure in getObjectOffset() when
PrologEpilogInserter tried to access the offset of a dead frame object.

The existing debug fixup code in SIFrameLowering and SILowerSGPRSpills
had two limitations:
1. It only checked one operand position, but DBG_VALUE_LIST instructions
can have multiple debug operands with frame indices.
2. It didn't handle all types of dead frame indices uniformly.

Fix by centralizing debug info cleanup in removeDeadFrameIndices(),
which already knows all frame indices being removed. This iterates over
all debug operands using MI.debug_operands().

Assisted-by: Claude Code.
2026-04-01 13:41:53 +01:00

35 lines
1.3 KiB
C++

//===- SISpillUtils.cpp - SI spill helper functions -----------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "SISpillUtils.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
using namespace llvm;
void llvm::clearDebugInfoForSpillFIs(MachineFrameInfo &MFI,
MachineBasicBlock &MBB,
const BitVector &SpillFIs) {
// FIXME: The dead frame indices are replaced with a null register from the
// debug value instructions. We should instead update it with the correct
// register value. But not sure the register value alone is adequate to lower
// the DIExpression. It should be worked out later.
for (MachineInstr &MI : MBB) {
if (!MI.isDebugValue())
continue;
for (MachineOperand &Op : MI.debug_operands()) {
if (Op.isFI() && !MFI.isFixedObjectIndex(Op.getIndex()) &&
SpillFIs[Op.getIndex()]) {
Op.ChangeToRegister(Register(), /*isDef=*/false);
}
}
}
}