[PATCH] D43207: [Utils] Salvage the debug info of DCE'ed 'xor' instructions

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 12 17:11:46 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL324973: [Utils] Salvage the debug info of DCE'ed 'xor' instructions (authored by vedantk, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43207?vs=133921&id=133965#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43207

Files:
  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


Index: llvm/trunk/test/Transforms/InstCombine/debuginfo-variables.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/debuginfo-variables.ll
+++ llvm/trunk/test/Transforms/InstCombine/debuginfo-variables.ll
@@ -17,10 +17,20 @@
   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)
 ; CHECK: !13 = !DILocation(line: 1, column: 1, scope: !5)
 
 ; 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)
Index: llvm/trunk/lib/Transforms/Utils/Local.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp
@@ -1536,17 +1536,27 @@
       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) {
Index: llvm/trunk/lib/IR/DebugInfoMetadata.cpp
===================================================================
--- llvm/trunk/lib/IR/DebugInfoMetadata.cpp
+++ llvm/trunk/lib/IR/DebugInfoMetadata.cpp
@@ -709,6 +709,7 @@
     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;
Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
@@ -346,6 +346,7 @@
     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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43207.133965.patch
Type: text/x-patch
Size: 3712 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180213/cf05b91a/attachment.bin>


More information about the llvm-commits mailing list