[llvm] r317825 - Preserve debug info when DAG-combinging (zext (truncate x)) -> (and x, mask).
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 9 11:50:20 PST 2017
Author: adrian
Date: Thu Nov 9 11:50:20 2017
New Revision: 317825
URL: http://llvm.org/viewvc/llvm-project?rev=317825&view=rev
Log:
Preserve debug info when DAG-combinging (zext (truncate x)) -> (and x, mask).
rdar://problem/27139077
Added:
llvm/trunk/test/DebugInfo/AArch64/dagcombine-zext.ll
Modified:
llvm/trunk/include/llvm/CodeGen/SelectionDAG.h
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAG.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAG.h?rev=317825&r1=317824&r2=317825&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/SelectionDAG.h (original)
+++ llvm/trunk/include/llvm/CodeGen/SelectionDAG.h Thu Nov 9 11:50:20 2017
@@ -1184,16 +1184,21 @@ public:
unsigned R, bool IsIndirect, const DebugLoc &DL,
unsigned O);
- /// Constant
+ /// Creates a constant SDDbgValue node.
SDDbgValue *getConstantDbgValue(DIVariable *Var, DIExpression *Expr,
const Value *C, const DebugLoc &DL,
unsigned O);
- /// FrameIndex
+ /// Creates a FrameIndex SDDbgValue node.
SDDbgValue *getFrameIndexDbgValue(DIVariable *Var, DIExpression *Expr,
unsigned FI, const DebugLoc &DL,
unsigned O);
+ /// Transfer debug values from one node to another, while optionally
+ /// generating fragment expressions for split-up values.
+ void transferDbgValues(SDValue From, SDValue To, unsigned OffsetInBits = 0,
+ unsigned SizeInBits = 0);
+
/// Remove the specified node from the system. If any of its
/// operands then becomes dead, remove them as well. Inform UpdateListener
/// for each node deleted.
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=317825&r1=317824&r2=317825&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Thu Nov 9 11:50:20 2017
@@ -7613,7 +7613,11 @@ SDValue DAGCombiner::visitZERO_EXTEND(SD
if (!LegalOperations || TLI.isOperationLegal(ISD::AND, VT)) {
SDValue Op = DAG.getAnyExtOrTrunc(N0.getOperand(0), SDLoc(N), VT);
AddToWorklist(Op.getNode());
- return DAG.getZeroExtendInReg(Op, SDLoc(N), MinVT.getScalarType());
+ SDValue And = DAG.getZeroExtendInReg(Op, SDLoc(N), MinVT.getScalarType());
+ // We may safely transfer the debug info describing the truncate node over
+ // to the equivalent and operation.
+ DAG.transferDbgValues(N0, And);
+ return And;
}
}
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp?rev=317825&r1=317824&r2=317825&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp Thu Nov 9 11:50:20 2017
@@ -835,34 +835,6 @@ void DAGTypeLegalizer::GetExpandedIntege
Hi = Entry.second;
}
-/// Transfer debug values by generating fragment expressions for split-up
-/// values.
-static void transferDbgValues(SelectionDAG &DAG, SDValue From, SDValue To,
- unsigned OffsetInBits) {
- SDNode *FromNode = From.getNode();
- SDNode *ToNode = To.getNode();
- assert(FromNode != ToNode);
-
- SmallVector<SDDbgValue *, 2> ClonedDVs;
- for (SDDbgValue *Dbg : DAG.GetDbgValues(FromNode)) {
- if (Dbg->getKind() != SDDbgValue::SDNODE)
- break;
-
- DIVariable *Var = Dbg->getVariable();
- if (auto Fragment = DIExpression::createFragmentExpression(
- Dbg->getExpression(), OffsetInBits, To.getValueSizeInBits())) {
- SDDbgValue *Clone = DAG.getDbgValue(Var, *Fragment, ToNode, To.getResNo(),
- Dbg->isIndirect(), Dbg->getDebugLoc(),
- Dbg->getOrder());
- ClonedDVs.push_back(Clone);
- }
- Dbg->setIsInvalidated();
- }
-
- for (SDDbgValue *Dbg : ClonedDVs)
- DAG.AddDbgValue(Dbg, ToNode, false);
-}
-
void DAGTypeLegalizer::SetExpandedInteger(SDValue Op, SDValue Lo,
SDValue Hi) {
assert(Lo.getValueType() ==
@@ -875,11 +847,13 @@ void DAGTypeLegalizer::SetExpandedIntege
// Transfer debug values.
if (DAG.getDataLayout().isBigEndian()) {
- transferDbgValues(DAG, Op, Hi, 0);
- transferDbgValues(DAG, Op, Lo, Hi.getValueSizeInBits());
+ DAG.transferDbgValues(Op, Hi, 0, Hi.getValueSizeInBits());
+ DAG.transferDbgValues(Op, Lo, Hi.getValueSizeInBits(),
+ Lo.getValueSizeInBits());
} else {
- transferDbgValues(DAG, Op, Lo, 0);
- transferDbgValues(DAG, Op, Hi, Lo.getValueSizeInBits());
+ DAG.transferDbgValues(Op, Lo, 0, Lo.getValueSizeInBits());
+ DAG.transferDbgValues(Op, Hi, Lo.getValueSizeInBits(),
+ Hi.getValueSizeInBits());
}
// Remember that this is the result of the node.
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=317825&r1=317824&r2=317825&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Thu Nov 9 11:50:20 2017
@@ -7026,6 +7026,41 @@ SDDbgValue *SelectionDAG::getFrameIndexD
return new (DbgInfo->getAlloc()) SDDbgValue(Var, Expr, FI, DL, O);
}
+void SelectionDAG::transferDbgValues(SDValue From, SDValue To,
+ unsigned OffsetInBits,
+ unsigned SizeInBits) {
+ SDNode *FromNode = From.getNode();
+ SDNode *ToNode = To.getNode();
+ assert(FromNode != ToNode);
+
+ SmallVector<SDDbgValue *, 2> ClonedDVs;
+ for (SDDbgValue *Dbg : GetDbgValues(FromNode)) {
+ if (Dbg->getKind() != SDDbgValue::SDNODE)
+ break;
+
+ DIVariable *Var = Dbg->getVariable();
+ auto *Expr = Dbg->getExpression();
+ // If a fragment is requested, update the expression.
+ if (SizeInBits) {
+ auto Fragment = DIExpression::createFragmentExpression(
+ Dbg->getExpression(), OffsetInBits, SizeInBits);
+ if (Fragment)
+ Expr = *Fragment;
+ }
+ // Clone the SbgValue unless the fragment creation failed.
+ if (!SizeInBits || (SizeInBits && Expr)) {
+ SDDbgValue *Clone =
+ getDbgValue(Var, Expr, ToNode, To.getResNo(), Dbg->isIndirect(),
+ Dbg->getDebugLoc(), Dbg->getOrder());
+ ClonedDVs.push_back(Clone);
+ }
+ Dbg->setIsInvalidated();
+ }
+
+ for (SDDbgValue *Dbg : ClonedDVs)
+ AddDbgValue(Dbg, ToNode, false);
+}
+
void SelectionDAG::salvageDebugInfo(SDNode &N) {
if (!N.getHasDebugValue())
return;
Added: llvm/trunk/test/DebugInfo/AArch64/dagcombine-zext.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/AArch64/dagcombine-zext.ll?rev=317825&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/AArch64/dagcombine-zext.ll (added)
+++ llvm/trunk/test/DebugInfo/AArch64/dagcombine-zext.ll Thu Nov 9 11:50:20 2017
@@ -0,0 +1,64 @@
+; RUN: llc -filetype=obj -o - %s | llvm-dwarfdump --name cntrl_flags - | FileCheck %s
+; CHECK: DW_OP_reg0 W0
+;
+; void use(unsigned char);
+; f(unsigned long long cntrl_flags,
+; int page_count)
+; {
+; unsigned char tag;
+; tag = (((cntrl_flags) >> 32) & 0xFF);
+; use(tag);
+; }
+
+source_filename = "test.i"
+target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
+target triple = "arm64-apple-ios5.0.0"
+
+; Function Attrs: nounwind ssp uwtable
+define i32 @f(i64 %cntrl_flags) local_unnamed_addr #0 !dbg !8 {
+entry:
+ tail call void @llvm.dbg.value(metadata i64 %cntrl_flags, metadata !14, metadata !DIExpression()), !dbg !18
+ %shr = lshr i64 %cntrl_flags, 32, !dbg !20
+ %conv = trunc i64 %shr to i8, !dbg !21
+ tail call void @llvm.dbg.value(metadata i8 %conv, metadata !16, metadata !DIExpression()), !dbg !22
+ tail call void @use(i8 zeroext %conv) #3, !dbg !23
+ ret i32 undef, !dbg !24
+}
+
+declare void @use(i8 zeroext) local_unnamed_addr
+
+; Function Attrs: nounwind readnone speculatable
+declare void @llvm.dbg.value(metadata, metadata, metadata) #2
+
+attributes #0 = { nounwind ssp uwtable }
+attributes #2 = { nounwind readnone speculatable }
+attributes #3 = { nobuiltin nounwind }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5, !6}
+!llvm.ident = !{!7}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 (trunk 317700) (llvm/trunk 317708)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "test.i", directory: "/")
+!2 = !{}
+!3 = !{i32 2, !"Dwarf Version", i32 2}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{i32 7, !"PIC Level", i32 2}
+!7 = !{!"clang version 6.0.0 (trunk 317700) (llvm/trunk 317708)"}
+!8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 2, type: !9, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !13)
+!9 = !DISubroutineType(types: !10)
+!10 = !{!11, !11}
+!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!12 = !DIBasicType(name: "long long unsigned int", size: 64, encoding: DW_ATE_unsigned)
+!13 = !{!14, !16}
+!14 = !DILocalVariable(name: "cntrl_flags", arg: 1, scope: !8, file: !1, line: 2, type: !12)
+!16 = !DILocalVariable(name: "tag", scope: !8, file: !1, line: 5, type: !17)
+!17 = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char)
+!18 = !DILocation(line: 2, column: 22, scope: !8)
+!19 = !DILocation(line: 3, column: 31, scope: !8)
+!20 = !DILocation(line: 6, column: 24, scope: !8)
+!21 = !DILocation(line: 6, column: 8, scope: !8)
+!22 = !DILocation(line: 5, column: 16, scope: !8)
+!23 = !DILocation(line: 7, column: 2, scope: !8)
+!24 = !DILocation(line: 8, column: 1, scope: !8)
More information about the llvm-commits
mailing list