From: Vedant Kumar Date: Tue, 13 Feb 2018 01:09:52 +0000 (+0000) Subject: [Utils] Salvage debug info of DCE'ed mul/sdiv/srem instructions X-Git-Tag: llvmorg-7.0.0-rc1~12993 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4011c26cc7cc3762a20d3927fc8cd80ad7b4d893;p=platform%2Fupstream%2Fllvm.git [Utils] Salvage debug info of DCE'ed mul/sdiv/srem instructions 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 --- diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp index 885e588..3b2eb41 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp @@ -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: diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp index fc3d344..ee3eaae 100644 --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -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: diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 1340e12..45962ca 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -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; diff --git a/llvm/test/Transforms/InstCombine/debuginfo-variables.ll b/llvm/test/Transforms/InstCombine/debuginfo-variables.ll index 09999c1..418ef81 100644 --- a/llvm/test/Transforms/InstCombine/debuginfo-variables.ll +++ b/llvm/test/Transforms/InstCombine/debuginfo-variables.ll @@ -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)