Skip to content

Commit e5dbea2

Browse files
Addressed review feedback
converted DW_OP_LLVM_fragment expr to a DW_OP_LLVM_convert expr
1 parent 44e346c commit e5dbea2

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"
@@ -14457,29 +14458,35 @@ static SDValue tryToFoldExtOfLoad(SelectionDAG &DAG, DAGCombiner &Combiner,
1445714458
LN0->getBasePtr(), N0.getValueType(),
1445814459
LN0->getMemOperand());
1445914460
Combiner.ExtendSetCCUses(SetCCs, N0, ExtLoad, ExtOpc);
14461+
unsigned Opcode = N->getOpcode();
14462+
bool IsSigned = Opcode == ISD::SIGN_EXTEND ? true : false;
1446014463
// If the load value is used only by N, replace it via CombineTo N.
1446114464
SDValue OldLoadVal(LN0, 0);
14462-
SDValue OldSextValue(N, 0);
14465+
SDValue OldExtValue(N, 0);
1446314466
bool NoReplaceTrunc = OldLoadVal.hasOneUse();
1446414467
Combiner.CombineTo(N, ExtLoad);
1446514468

1446614469
// Because we are replacing a load and a sext with a load-sext instruction,
1446714470
// the dbg_value attached to the load will be of a smaller bit width, and we
1446814471
// have to add a DW_OP_LLVM_fragment to the DIExpression.
14469-
auto SalvageToOldLoadSize = [&](SDValue From, SDValue To64) {
14472+
auto SalvageToOldLoadSize = [&](SDValue From, SDValue To, bool IsSigned) {
1447014473
for (SDDbgValue *Dbg : DAG.GetDbgValues(From.getNode())) {
14471-
unsigned VarBits = From->getValueSizeInBits(0);
14474+
unsigned VarBitsFrom = From->getValueSizeInBits(0);
14475+
unsigned VarBitsTo = To->getValueSizeInBits(0);
1447214476

14473-
// Build/append a fragment expression [0, VarBits]
14477+
// Build a convert expression for the s|z extend.
1447414478
const DIExpression *OldE = Dbg->getExpression();
14475-
auto NewE = DIExpression::createFragmentExpression(OldE, 0, VarBits);
14476-
14477-
// Create a new SDDbgValue that points at the widened node with the
14478-
// fragment.
14479-
if (!NewE)
14480-
continue;
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.
1448114488
SDDbgValue *NewDV = DAG.getDbgValue(
14482-
Dbg->getVariable(), *NewE, To64.getNode(), To64.getResNo(),
14489+
Dbg->getVariable(), NewE, To.getNode(), To.getResNo(),
1448314490
Dbg->isIndirect(), Dbg->getDebugLoc(), Dbg->getOrder());
1448414491
DAG.AddDbgValue(NewDV, /*isParametet*/ false);
1448514492
}
@@ -14488,21 +14495,21 @@ static SDValue tryToFoldExtOfLoad(SelectionDAG &DAG, DAGCombiner &Combiner,
1448814495
if (NoReplaceTrunc) {
1448914496
if (LN0->getHasDebugValue()) {
1449014497
DAG.transferDbgValues(OldLoadVal, ExtLoad);
14491-
SalvageToOldLoadSize(OldLoadVal, ExtLoad);
14498+
SalvageToOldLoadSize(OldLoadVal, ExtLoad, IsSigned);
1449214499
}
1449314500
if (N->getHasDebugValue())
14494-
DAG.transferDbgValues(OldSextValue, ExtLoad);
14501+
DAG.transferDbgValues(OldExtValue, ExtLoad);
1449514502
DAG.ReplaceAllUsesOfValueWith(SDValue(LN0, 1), ExtLoad.getValue(1));
1449614503
Combiner.recursivelyDeleteUnusedNodes(LN0);
1449714504
} else {
1449814505
SDValue Trunc =
1449914506
DAG.getNode(ISD::TRUNCATE, SDLoc(N0), N0.getValueType(), ExtLoad);
1450014507
if (LN0->getHasDebugValue()) {
1450114508
DAG.transferDbgValues(OldLoadVal, Trunc);
14502-
SalvageToOldLoadSize(OldLoadVal, Trunc);
14509+
SalvageToOldLoadSize(OldLoadVal, Trunc, IsSigned);
1450314510
}
1450414511
if (N->getHasDebugValue())
14505-
DAG.transferDbgValues(OldSextValue, Trunc);
14512+
DAG.transferDbgValues(OldExtValue, Trunc);
1450614513
Combiner.CombineTo(LN0, Trunc, ExtLoad.getValue(1));
1450714514
}
1450814515
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)