Skip to content

Commit 2e7afe8

Browse files
Addressed review feedback
converted DW_OP_LLVM_fragment expr to a DW_OP_LLVM_convert expr
1 parent fcc66bd commit 2e7afe8

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "llvm/Analysis/TargetLibraryInfo.h"
3333
#include "llvm/Analysis/ValueTracking.h"
3434
#include "llvm/Analysis/VectorUtils.h"
35+
#include "llvm/BinaryFormat/Dwarf.h"
3536
#include "llvm/CodeGen/ByteProvider.h"
3637
#include "llvm/CodeGen/DAGCombine.h"
3738
#include "llvm/CodeGen/ISDOpcodes.h"
@@ -14445,29 +14446,35 @@ static SDValue tryToFoldExtOfLoad(SelectionDAG &DAG, DAGCombiner &Combiner,
1444514446
LN0->getBasePtr(), N0.getValueType(),
1444614447
LN0->getMemOperand());
1444714448
Combiner.ExtendSetCCUses(SetCCs, N0, ExtLoad, ExtOpc);
14449+
unsigned Opcode = N->getOpcode();
14450+
bool IsSigned = Opcode == ISD::SIGN_EXTEND ? true : false;
1444814451
// If the load value is used only by N, replace it via CombineTo N.
1444914452
SDValue OldLoadVal(LN0, 0);
14450-
SDValue OldSextValue(N, 0);
14453+
SDValue OldExtValue(N, 0);
1445114454
bool NoReplaceTrunc = OldLoadVal.hasOneUse();
1445214455
Combiner.CombineTo(N, ExtLoad);
1445314456

1445414457
// Because we are replacing a load and a sext with a load-sext instruction,
1445514458
// the dbg_value attached to the load will be of a smaller bit width, and we
1445614459
// have to add a DW_OP_LLVM_fragment to the DIExpression.
14457-
auto SalvageToOldLoadSize = [&](SDValue From, SDValue To64) {
14460+
auto SalvageToOldLoadSize = [&](SDValue From, SDValue To, bool IsSigned) {
1445814461
for (SDDbgValue *Dbg : DAG.GetDbgValues(From.getNode())) {
14459-
unsigned VarBits = From->getValueSizeInBits(0);
14462+
unsigned VarBitsFrom = From->getValueSizeInBits(0);
14463+
unsigned VarBitsTo = To->getValueSizeInBits(0);
1446014464

14461-
// Build/append a fragment expression [0, VarBits]
14465+
// Build a convert expression for the s|z extend.
1446214466
const DIExpression *OldE = Dbg->getExpression();
14463-
auto NewE = DIExpression::createFragmentExpression(OldE, 0, VarBits);
14464-
14465-
// Create a new SDDbgValue that points at the widened node with the
14466-
// fragment.
14467-
if (!NewE)
14468-
continue;
14467+
SmallVector<uint64_t, 8> Ops;
14468+
dwarf::TypeKind TK =
14469+
IsSigned ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned;
14470+
Ops.append({dwarf::DW_OP_LLVM_convert, VarBitsFrom, TK,
14471+
dwarf::DW_OP_LLVM_convert, VarBitsTo, TK});
14472+
auto *NewE = DIExpression::get(OldE->getContext(), Ops);
14473+
14474+
// // Create a new SDDbgValue that points at the widened node with the
14475+
// // fragment.
1446914476
SDDbgValue *NewDV = DAG.getDbgValue(
14470-
Dbg->getVariable(), *NewE, To64.getNode(), To64.getResNo(),
14477+
Dbg->getVariable(), NewE, To.getNode(), To.getResNo(),
1447114478
Dbg->isIndirect(), Dbg->getDebugLoc(), Dbg->getOrder());
1447214479
DAG.AddDbgValue(NewDV, /*isParametet*/ false);
1447314480
}
@@ -14476,21 +14483,21 @@ static SDValue tryToFoldExtOfLoad(SelectionDAG &DAG, DAGCombiner &Combiner,
1447614483
if (NoReplaceTrunc) {
1447714484
if (LN0->getHasDebugValue()) {
1447814485
DAG.transferDbgValues(OldLoadVal, ExtLoad);
14479-
SalvageToOldLoadSize(OldLoadVal, ExtLoad);
14486+
SalvageToOldLoadSize(OldLoadVal, ExtLoad, IsSigned);
1448014487
}
1448114488
if (N->getHasDebugValue())
14482-
DAG.transferDbgValues(OldSextValue, ExtLoad);
14489+
DAG.transferDbgValues(OldExtValue, ExtLoad);
1448314490
DAG.ReplaceAllUsesOfValueWith(SDValue(LN0, 1), ExtLoad.getValue(1));
1448414491
Combiner.recursivelyDeleteUnusedNodes(LN0);
1448514492
} else {
1448614493
SDValue Trunc =
1448714494
DAG.getNode(ISD::TRUNCATE, SDLoc(N0), N0.getValueType(), ExtLoad);
1448814495
if (LN0->getHasDebugValue()) {
1448914496
DAG.transferDbgValues(OldLoadVal, Trunc);
14490-
SalvageToOldLoadSize(OldLoadVal, Trunc);
14497+
SalvageToOldLoadSize(OldLoadVal, Trunc, IsSigned);
1449114498
}
1449214499
if (N->getHasDebugValue())
14493-
DAG.transferDbgValues(OldSextValue, Trunc);
14500+
DAG.transferDbgValues(OldExtValue, Trunc);
1449414501
Combiner.CombineTo(LN0, Trunc, ExtLoad.getValue(1));
1449514502
}
1449614503
return SDValue(N, 0); // Return N so it doesn't get rechecked!

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
# MIR: ![[IDX:[0-9]+]] = !DILocalVariable(name: "Idx"
88
# MIR-LABEL: bb.0
9-
# MIR: %{{[0-9a-zA-Z]+}}{{.*}} = MOVSX64rm32 ${{.*}}, 1, $noreg, @GlobArr, $noreg, debug-instr-number [[INSTR_NUM:[0-9]+]]
9+
# MIR: %{{[0-9a-f]+}}{{.*}} = MOVSX64rm32 ${{.*}}, 1, $noreg, @GlobArr, $noreg, debug-instr-number [[INSTR_NUM:[0-9]+]]
1010
# MIR-NEXT: DBG_INSTR_REF ![[IDX]], !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref([[INSTR_NUM]], 0)
11-
# MIR-NEXT: DBG_INSTR_REF ![[IDX]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 0, 32), dbg-instr-ref([[INSTR_NUM]], 0)
11+
# 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)
1212

13-
# DUMP: DW_AT_location (indexed ({{[0-9]+}}x{{[0-9]+}}) loclist = 0x{{[0-9]+}}:
14-
# DUMP-NEXT: [0x{{[0-9]+}}, 0x{{[0-9]+}}): {{.*}}, DW_OP_piece 0x4
13+
# DUMP: DW_AT_location (indexed ({{[0-9a-f]+}}x{{[0-9a-f]+}}) loclist = 0x{{[0-9]+}}:
14+
# DUMP-NEXT: [0x{{[0-9a-f]+}}, 0x{{[0-9a-f]+}}): DW_OP_breg0 RAX+0, DW_OP_convert (0x{{[0-9a-f]+}}) "DW_ATE_signed_32", DW_OP_convert (0x{{[0-9a-f]+}}) "DW_ATE_signed_64")
1515

1616
--- |
1717
@GlobArr = dso_local local_unnamed_addr global [5 x i32] [i32 1, i32 1, i32 2, i32 3, i32 5], align 16, !dbg !0

0 commit comments

Comments
 (0)