[Utils] Salvage debug info of DCE'ed mul/sdiv/srem instructions
authorVedant Kumar <vsk@apple.com>
Tue, 13 Feb 2018 01:09:52 +0000 (01:09 +0000)
committerVedant Kumar <vsk@apple.com>
Tue, 13 Feb 2018 01:09:52 +0000 (01:09 +0000)
Here are the number of additional debug values salvaged in a stage2
build of clang:

  63 SALVAGE: MUL
  1250 SALVAGE: SDIV

(No values were salvaged from `srem` instructions in this experiment,
but it's a simple case to handle so we might as well.)

llvm-svn: 324976

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 885e588..3b2eb41 100644 (file)
@@ -345,6 +345,8 @@ void DwarfExpression::addExpression(DIExpressionCursor &&ExprCursor,
     case dwarf::DW_OP_plus:
     case dwarf::DW_OP_minus:
     case dwarf::DW_OP_mul:
+    case dwarf::DW_OP_div:
+    case dwarf::DW_OP_mod:
     case dwarf::DW_OP_or:
     case dwarf::DW_OP_xor:
     case dwarf::DW_OP_shl:
index fc3d344..ee3eaae 100644 (file)
@@ -708,6 +708,8 @@ bool DIExpression::isValid() const {
     case dwarf::DW_OP_plus:
     case dwarf::DW_OP_minus:
     case dwarf::DW_OP_mul:
+    case dwarf::DW_OP_div:
+    case dwarf::DW_OP_mod:
     case dwarf::DW_OP_or:
     case dwarf::DW_OP_xor:
     case dwarf::DW_OP_shl:
index 1340e12..45962ca 100644 (file)
@@ -1549,6 +1549,15 @@ void llvm::salvageDebugInfo(Instruction &I) {
       case Instruction::Sub:
         applyOffset(DII, -int64_t(Val));
         break;
+      case Instruction::Mul:
+        applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_mul});
+        break;
+      case Instruction::SDiv:
+        applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_div});
+        break;
+      case Instruction::SRem:
+        applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_mod});
+        break;
       case Instruction::Or:
         applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_or});
         break;
index 09999c1..418ef81 100644 (file)
@@ -59,6 +59,27 @@ define void @test_ashr(i64 %A) {
   ret void
 }
 
+define void @test_mul(i64 %A) {
+; CHECK-LABEL: @test_mul(
+; CHECK-NEXT:  call void @llvm.dbg.value(metadata i64 %A, metadata !52, metadata !DIExpression(DW_OP_constu, 7, DW_OP_mul, DW_OP_stack_value)), !dbg !53
+  %1 = mul i64 %A, 7
+  ret void
+}
+
+define void @test_sdiv(i64 %A) {
+; CHECK-LABEL: @test_sdiv(
+; CHECK-NEXT:  call void @llvm.dbg.value(metadata i64 %A, metadata !57, metadata !DIExpression(DW_OP_constu, 7, DW_OP_div, DW_OP_stack_value)), !dbg !58
+  %1 = sdiv i64 %A, 7
+  ret void
+}
+
+define void @test_srem(i64 %A) {
+; CHECK-LABEL: @test_srem(
+; CHECK-NEXT:  call void @llvm.dbg.value(metadata i64 %A, metadata !62, metadata !DIExpression(DW_OP_constu, 7, DW_OP_mod, DW_OP_stack_value)), !dbg !63
+  %1 = srem i64 %A, 7
+  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)
@@ -84,3 +105,12 @@ define void @test_ashr(i64 %A) {
 
 ; CHECK: !47 = !DILocalVariable(name: "9", scope: !45, file: !1, line: 16, type: !11)
 ; CHECK: !48 = !DILocation(line: 16, column: 1, scope: !45)
+
+; CHECK: !52 = !DILocalVariable(name: "10", scope: !50, file: !1, line: 18, type: !11)
+; CHECK: !53 = !DILocation(line: 18, column: 1, scope: !50)
+
+; CHECK: !57 = !DILocalVariable(name: "11", scope: !55, file: !1, line: 20, type: !11)
+; CHECK: !58 = !DILocation(line: 20, column: 1, scope: !55)
+
+; CHECK: !62 = !DILocalVariable(name: "12", scope: !60, file: !1, line: 22, type: !11)
+; CHECK: !63 = !DILocation(line: 22, column: 1, scope: !60)