[Utils] Salvage the debug info of DCE'ed 'and' instructions
authorPetar Jovanovic <petar.jovanovic@mips.com>
Wed, 14 Feb 2018 13:10:35 +0000 (13:10 +0000)
committerPetar Jovanovic <petar.jovanovic@mips.com>
Wed, 14 Feb 2018 13:10:35 +0000 (13:10 +0000)
Preserve debug info from a dead 'and' instruction with a constant.

Patch by Djordje Todorovic.

Differential Revision: https://reviews.llvm.org/D43163

llvm-svn: 325119

llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
llvm/lib/IR/DebugInfoMetadata.cpp
llvm/lib/Transforms/Utils/Local.cpp
llvm/test/Transforms/InstCombine/debuginfo-variables.ll

index f626c37..379e9b1 100644 (file)
@@ -352,6 +352,7 @@ void DwarfExpression::addExpression(DIExpressionCursor &&ExprCursor,
     case dwarf::DW_OP_div:
     case dwarf::DW_OP_mod:
     case dwarf::DW_OP_or:
+    case dwarf::DW_OP_and:
     case dwarf::DW_OP_xor:
     case dwarf::DW_OP_shl:
     case dwarf::DW_OP_shr:
index ee3eaae..82f04a6 100644 (file)
@@ -711,6 +711,7 @@ bool DIExpression::isValid() const {
     case dwarf::DW_OP_div:
     case dwarf::DW_OP_mod:
     case dwarf::DW_OP_or:
+    case dwarf::DW_OP_and:
     case dwarf::DW_OP_xor:
     case dwarf::DW_OP_shl:
     case dwarf::DW_OP_shr:
index 34f7d41..39d66e0 100644 (file)
@@ -1564,6 +1564,9 @@ void llvm::salvageDebugInfo(Instruction &I) {
       case Instruction::Or:
         applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_or});
         break;
+      case Instruction::And:
+        applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_and});
+        break;
       case Instruction::Xor:
         applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_xor});
         break;
index d420346..5c11523 100644 (file)
@@ -87,6 +87,13 @@ define void @test_ptrtoint(i64* %P) {
   ret void
 }
 
+define void @test_and(i64 %A) {
+; CHECK-LABEL: @test_and(
+; CHECK-NEXT:  call void @llvm.dbg.value(metadata i64 %A, metadata !72, metadata !DIExpression(DW_OP_constu, 256, DW_OP_and, DW_OP_stack_value)), !dbg !73
+  %1 = and i64 %A, 256
+  ret void
+}
+
 ; CHECK: !8 = !DILocalVariable(name: "1", scope: !5, file: !1, line: 1, type: !9)
 ; CHECK: !10 = !DILocalVariable(name: "2", scope: !5, file: !1, line: 2, type: !11)
 ; CHECK: !12 = !DILocation(line: 2, column: 1, scope: !5)
@@ -124,3 +131,6 @@ define void @test_ptrtoint(i64* %P) {
 
 ; CHECK: !67 = !DILocalVariable(name: "13", scope: !65, file: !1, line: 24, type: !11)
 ; CHECK: !68 = !DILocation(line: 24, column: 1, scope: !65)
+
+; CHECK: !72 = !DILocalVariable(name: "14", scope: !70, file: !1, line: 26, type: !11)
+; CHECK: !73 = !DILocation(line: 26, column: 1, scope: !70)