[llvm] r324973 - [Utils] Salvage the debug info of DCE'ed 'xor' instructions

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 12 17:09:46 PST 2018


Author: vedantk
Date: Mon Feb 12 17:09:46 2018
New Revision: 324973

URL: http://llvm.org/viewvc/llvm-project?rev=324973&view=rev
Log:
[Utils] Salvage the debug info of DCE'ed 'xor' instructions

This salvages 259 debug values in a stage2 build of clang.

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

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

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp?rev=324973&r1=324972&r2=324973&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp Mon Feb 12 17:09:46 2018
@@ -346,6 +346,7 @@ void DwarfExpression::addExpression(DIEx
     case dwarf::DW_OP_minus:
     case dwarf::DW_OP_mul:
     case dwarf::DW_OP_or:
+    case dwarf::DW_OP_xor:
       emitOp(Op->getOp());
       break;
     case dwarf::DW_OP_deref:

Modified: llvm/trunk/lib/IR/DebugInfoMetadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfoMetadata.cpp?rev=324973&r1=324972&r2=324973&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfoMetadata.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfoMetadata.cpp Mon Feb 12 17:09:46 2018
@@ -709,6 +709,7 @@ bool DIExpression::isValid() const {
     case dwarf::DW_OP_minus:
     case dwarf::DW_OP_mul:
     case dwarf::DW_OP_or:
+    case dwarf::DW_OP_xor:
     case dwarf::DW_OP_deref:
     case dwarf::DW_OP_xderef:
       break;

Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=324973&r1=324972&r2=324973&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Mon Feb 12 17:09:46 2018
@@ -1536,17 +1536,27 @@ void llvm::salvageDebugInfo(Instruction
       for (auto *DII : DbgUsers)
         applyOffset(DII, Offset.getSExtValue());
   } else if (auto *BI = dyn_cast<BinaryOperator>(&I)) {
-    if (BI->getOpcode() == Instruction::Add ||
-        BI->getOpcode() == Instruction::Or)
-      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});
-        }
+    auto *ConstInt = dyn_cast<ConstantInt>(I.getOperand(1));
+    if (!ConstInt || ConstInt->getBitWidth() > 64)
+      return;
+
+    uint64_t Val = ConstInt->getSExtValue();
+    for (auto *DII : DbgUsers) {
+      switch (BI->getOpcode()) {
+      case Instruction::Add:
+        applyOffset(DII, Val);
+        break;
+      case Instruction::Or:
+        applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_or});
+        break;
+      case Instruction::Xor:
+        applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_xor});
+        break;
+      default:
+        // TODO: Salvage constants from each kind of binop we know about.
+        continue;
+      }
+    }
   } else if (isa<LoadInst>(&I)) {
     MetadataAsValue *AddrMD = wrapMD(I.getOperand(0));
     for (auto *DII : DbgUsers) {

Modified: llvm/trunk/test/Transforms/InstCombine/debuginfo-variables.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/debuginfo-variables.ll?rev=324973&r1=324972&r2=324973&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/debuginfo-variables.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/debuginfo-variables.ll Mon Feb 12 17:09:46 2018
@@ -17,6 +17,13 @@ define void @test_or(i64 %A) {
   ret void
 }
 
+define void @test_xor(i32 %A) {
+; CHECK-LABEL: @test_xor(
+; CHECK-NEXT:  call void @llvm.dbg.value(metadata i32 %A, metadata !22, metadata !DIExpression(DW_OP_constu, 1, DW_OP_xor, DW_OP_stack_value)), !dbg !23
+  %1 = xor i32 %A, 1
+  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)
@@ -24,3 +31,6 @@ define void @test_or(i64 %A) {
 
 ; CHECK: !17 = !DILocalVariable(name: "3", scope: !15, file: !1, line: 4, type: !11)
 ; CHECK: !18 = !DILocation(line: 4, column: 1, scope: !15)
+
+; CHECK: !22 = !DILocalVariable(name: "4", scope: !20, file: !1, line: 6, type: !9)
+; CHECK: !23 = !DILocation(line: 6, column: 1, scope: !20)




More information about the llvm-commits mailing list