[PATCH] D43163: [Utils] Salvage the debug info of DCE'ed ‘and’ instructions
Djordje Todorovic via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 10 11:27:19 PST 2018
djtodoro created this revision.
djtodoro added a reviewer: aprantl.
djtodoro added a project: debug-info.
Herald added subscribers: llvm-commits, JDevlieghere.
Preserve debug info from a dead ‘and’ instruction with a constant.
Repository:
rL LLVM
https://reviews.llvm.org/D43163
Files:
lib/CodeGen/AsmPrinter/DwarfExpression.cpp
lib/IR/DebugInfoMetadata.cpp
lib/Transforms/Utils/Local.cpp
test/Transforms/InstCombine/debuginfo-dce-and.ll
Index: test/Transforms/InstCombine/debuginfo-dce-and.ll
===================================================================
--- /dev/null
+++ test/Transforms/InstCombine/debuginfo-dce-and.ll
@@ -0,0 +1,42 @@
+; RUN: opt -instcombine %s -o - -S | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @fn1(i64 %v1) !dbg !9 {
+entry:
+ %0 = and i64 %v1, 128, !dbg !18
+; CHECK: call void @llvm.dbg.value(metadata i64 %v1,
+; CHECK-SAME: metadata !DIExpression(DW_OP_constu, 128, DW_OP_and, DW_OP_stack_value))
+ call void @llvm.dbg.value(metadata i64 %0, metadata !14, metadata !16), !dbg !19
+ ret void, !dbg !20
+}
+
+declare void @llvm.dbg.value(metadata, metadata, metadata) #0
+
+attributes #0 = { nounwind readnone }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!5, !6, !7}
+!llvm.ident = !{!8}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 7.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3)
+!1 = !DIFile(filename: "dce-and.c", directory: "/dir")
+!2 = !{}
+!3 = !{}
+!4 = !DIBasicType(name: "long long int", size: 64, encoding: DW_ATE_signed)
+!5 = !{i32 2, !"Dwarf Version", i32 4}
+!6 = !{i32 2, !"Debug Info Version", i32 3}
+!7 = !{i32 1, !"PIC Level", i32 2}
+!8 = !{!"clang version 7.0.0"}
+!9 = distinct !DISubprogram(name: "fn1", scope: !1, file: !1, line: 91, type: !10, isLocal: false, isDefinition: true, scopeLine: 93, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !12)
+!10 = !DISubroutineType(types: !11)
+!11 = !{!4}
+!12 = !{!13, !14}
+!13 = !DILocalVariable(name: "v1", arg: 2, scope: !9, file: !1, line: 92, type: !4)
+!14 = !DILocalVariable(name: "v2", scope: !9, file: !1, line: 94, type: !4)
+!15 = !{}
+!16 = !DIExpression()
+!17 = !DILexicalBlockFile(scope: !9, file: !1, discriminator: 2)
+!18 = !DILocation(line: 12, column: 13, scope: !17)
+!19 = !DILocation(line: 12, column: 13, scope: !9)
+!20 = !DILocation(line: 14, column: 1, scope: !9)
Index: lib/Transforms/Utils/Local.cpp
===================================================================
--- lib/Transforms/Utils/Local.cpp
+++ lib/Transforms/Utils/Local.cpp
@@ -1537,15 +1537,18 @@
applyOffset(DII, Offset.getSExtValue());
} else if (auto *BI = dyn_cast<BinaryOperator>(&I)) {
if (BI->getOpcode() == Instruction::Add ||
- BI->getOpcode() == Instruction::Or)
+ BI->getOpcode() == Instruction::Or ||
+ BI->getOpcode() == Instruction::And)
if (auto *ConstInt = dyn_cast<ConstantInt>(I.getOperand(1)))
if (ConstInt->getBitWidth() <= 64) {
uint64_t Val = ConstInt->getSExtValue();
for (auto *DII : DbgUsers)
if (BI->getOpcode() == Instruction::Add)
applyOffset(DII, Val);
else if (BI->getOpcode() == Instruction::Or)
applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_or});
+ else if (BI->getOpcode() == Instruction::And)
+ applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_and});
}
} else if (isa<LoadInst>(&I)) {
MetadataAsValue *AddrMD = wrapMD(I.getOperand(0));
Index: lib/IR/DebugInfoMetadata.cpp
===================================================================
--- lib/IR/DebugInfoMetadata.cpp
+++ lib/IR/DebugInfoMetadata.cpp
@@ -707,6 +707,7 @@
case dwarf::DW_OP_minus:
case dwarf::DW_OP_mul:
case dwarf::DW_OP_or:
+ case dwarf::DW_OP_and:
case dwarf::DW_OP_deref:
case dwarf::DW_OP_xderef:
break;
Index: lib/CodeGen/AsmPrinter/DwarfExpression.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ lib/CodeGen/AsmPrinter/DwarfExpression.cpp
@@ -342,6 +342,7 @@
case dwarf::DW_OP_minus:
case dwarf::DW_OP_mul:
case dwarf::DW_OP_or:
+ case dwarf::DW_OP_and:
emitOp(Op->getOp());
break;
case dwarf::DW_OP_deref:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43163.133762.patch
Type: text/x-patch
Size: 4008 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180210/dac5739c/attachment.bin>
More information about the llvm-commits
mailing list