Skip to content

Commit 363ab5e

Browse files
Addressed review feedback:
1. Moved the salvage code to selectionDAG::salvageDebugInfo, this also ensures that the old SDDbgValue is invalidated and removed.
1 parent a5e79b9 commit 363ab5e

File tree

3 files changed

+43
-31
lines changed

3 files changed

+43
-31
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14458,44 +14458,17 @@ static SDValue tryToFoldExtOfLoad(SelectionDAG &DAG, DAGCombiner &Combiner,
1445814458
LN0->getBasePtr(), N0.getValueType(),
1445914459
LN0->getMemOperand());
1446014460
Combiner.ExtendSetCCUses(SetCCs, N0, ExtLoad, ExtOpc);
14461-
unsigned Opcode = N->getOpcode();
14462-
bool IsSigned = Opcode == ISD::SIGN_EXTEND ? true : false;
14461+
1446314462
// If the load value is used only by N, replace it via CombineTo N.
1446414463
SDValue OldLoadVal(LN0, 0);
1446514464
SDValue OldExtValue(N, 0);
1446614465
bool NoReplaceTrunc = OldLoadVal.hasOneUse();
1446714466
Combiner.CombineTo(N, ExtLoad);
1446814467

14469-
// Because we are replacing a load and a sext with a load-sext instruction,
14470-
// the dbg_value attached to the load will be of a smaller bit width, and we
14471-
// have to add a DW_OP_LLVM_fragment to the DIExpression.
14472-
auto SalvageToOldLoadSize = [&](SDValue From, SDValue To, bool IsSigned) {
14473-
for (SDDbgValue *Dbg : DAG.GetDbgValues(From.getNode())) {
14474-
unsigned VarBitsFrom = From->getValueSizeInBits(0);
14475-
unsigned VarBitsTo = To->getValueSizeInBits(0);
14476-
14477-
// Build a convert expression for the s|z extend.
14478-
const DIExpression *OldE = Dbg->getExpression();
14479-
SmallVector<uint64_t, 8> Ops;
14480-
dwarf::TypeKind TK =
14481-
IsSigned ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned;
14482-
Ops.append({dwarf::DW_OP_LLVM_convert, VarBitsFrom, TK,
14483-
dwarf::DW_OP_LLVM_convert, VarBitsTo, TK});
14484-
auto *NewE = DIExpression::get(OldE->getContext(), Ops);
14485-
14486-
// // Create a new SDDbgValue that points at the widened node with the
14487-
// // fragment.
14488-
SDDbgValue *NewDV = DAG.getDbgValue(
14489-
Dbg->getVariable(), NewE, To.getNode(), To.getResNo(),
14490-
Dbg->isIndirect(), Dbg->getDebugLoc(), Dbg->getOrder());
14491-
DAG.AddDbgValue(NewDV, /*isParametet*/ false);
14492-
}
14493-
};
14494-
1449514468
if (NoReplaceTrunc) {
1449614469
if (LN0->getHasDebugValue()) {
1449714470
DAG.transferDbgValues(OldLoadVal, ExtLoad);
14498-
SalvageToOldLoadSize(OldLoadVal, ExtLoad, IsSigned);
14471+
DAG.salvageDebugInfo(*ExtLoad.getNode());
1449914472
}
1450014473
if (N->getHasDebugValue())
1450114474
DAG.transferDbgValues(OldExtValue, ExtLoad);
@@ -14506,7 +14479,7 @@ static SDValue tryToFoldExtOfLoad(SelectionDAG &DAG, DAGCombiner &Combiner,
1450614479
DAG.getNode(ISD::TRUNCATE, SDLoc(N0), N0.getValueType(), ExtLoad);
1450714480
if (LN0->getHasDebugValue()) {
1450814481
DAG.transferDbgValues(OldLoadVal, Trunc);
14509-
SalvageToOldLoadSize(OldLoadVal, Trunc, IsSigned);
14482+
DAG.salvageDebugInfo(*Trunc.getNode());
1451014483
}
1451114484
if (N->getHasDebugValue())
1451214485
DAG.transferDbgValues(OldExtValue, Trunc);

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12123,6 +12123,46 @@ void SelectionDAG::salvageDebugInfo(SDNode &N) {
1212312123
dbgs() << " into " << *DbgExpression << '\n');
1212412124
break;
1212512125
}
12126+
case ISD::LOAD: {
12127+
SDValue N0 = N.getOperand(0);
12128+
if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(&N)) {
12129+
12130+
// Currently, this is written to only work for S|Z EXT.
12131+
if (LD->getExtensionType() == ISD::NON_EXTLOAD ||
12132+
LD->getExtensionType() == ISD::EXTLOAD)
12133+
break;
12134+
12135+
// Because we are replacing a load and a s|zext with a load-s|zext
12136+
// instruction, the dbg_value attached to the load will be of a smaller
12137+
// bit width, and we have to add a DW_OP_LLVM_fragment to the
12138+
// DIExpression.
12139+
unsigned VarBitsTo = LD->getValueSizeInBits(0);
12140+
unsigned VarBitsFrom = LD->getMemoryVT().getSizeInBits();
12141+
bool IsSigned = LD->getExtensionType() == ISD::SEXTLOAD;
12142+
12143+
// Build a convert expression for the s|z extend.
12144+
const DIExpression *OldE = DV->getExpression();
12145+
SmallVector<uint64_t, 8> Ops;
12146+
dwarf::TypeKind TK =
12147+
IsSigned ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned;
12148+
Ops.append({dwarf::DW_OP_LLVM_convert, VarBitsFrom, TK,
12149+
dwarf::DW_OP_LLVM_convert, VarBitsTo, TK});
12150+
auto *NewE = DIExpression::get(OldE->getContext(), Ops);
12151+
12152+
// Create a new SDDbgValue that points at the widened node with the
12153+
// fragment.
12154+
SDDbgValue *NewDV =
12155+
getDbgValue(DV->getVariable(), NewE, &N, N0.getResNo(),
12156+
DV->isIndirect(), DV->getDebugLoc(), DV->getOrder());
12157+
ClonedDVs.push_back(NewDV);
12158+
DV->setIsInvalidated();
12159+
DV->setIsEmitted();
12160+
LLVM_DEBUG(dbgs() << "SALVAGE: Rewriting";
12161+
N0.getNode()->dumprFull(this);
12162+
dbgs() << " into " << *NewE << '\n');
12163+
break;
12164+
}
12165+
}
1212612166
}
1212712167
}
1212812168

llvm/test/DebugInfo/X86/selectionDAG-load-sext.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
; MIR: ![[IDX:[0-9]+]] = !DILocalVariable(name: "Idx"
88
; MIR-LABEL: bb.0
99
; MIR: %{{[0-9a-f]+}}{{.*}} = MOVSX64rm32 ${{.*}}, 1, $noreg, @GlobArr, $noreg, debug-instr-number [[INSTR_NUM:[0-9]+]]
10-
; MIR-NEXT: DBG_INSTR_REF ![[IDX]], !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref([[INSTR_NUM]], 0)
1110
; MIR-NEXT: DBG_INSTR_REF ![[IDX]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_convert, 32, DW_ATE_signed, DW_OP_LLVM_convert, 64, DW_ATE_signed), dbg-instr-ref([[INSTR_NUM]], 0)
1211

1312
; DUMP: DW_AT_location (indexed ({{[0-9a-f]+}}x{{[0-9a-f]+}}) loclist = 0x{{[0-9]+}}:

0 commit comments

Comments
 (0)