summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmed Bougacha <ahmed.bougacha@gmail.com>2017-03-21 23:42:54 +0000
committerAhmed Bougacha <ahmed.bougacha@gmail.com>2017-03-21 23:42:54 +0000
commit15b3e8a93a4040238f4f7655a7b23a2f50716af8 (patch)
tree82040291134652063d1f85b414ac62acb61e3f14
parente8e1fa3a7cf8a9500a39702cce71cde8aa2960f0 (diff)
downloadbcm5719-llvm-15b3e8a93a4040238f4f7655a7b23a2f50716af8.tar.gz
bcm5719-llvm-15b3e8a93a4040238f4f7655a7b23a2f50716af8.zip
[GlobalISel] Update DBG_VALUEs referencing DCE'd instructions.
Quentin points out that r298358 would cause us to emit different code with debug info. That's a big no-no; also erase the instructions that only live thanks to DBG_VALUE users. Adrian explained how this is an existing problem and an OK thing to do: clang has allocas for all variables so shouldn't be affected at -O0, but swift uses a bit of inlineasm to explicitly keep values live for the purpose of debug info quality. I'm not sure there is a better scheme. llvm-svn: 298460
-rw-r--r--llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp2
-rw-r--r--llvm/lib/CodeGen/GlobalISel/Utils.cpp4
-rw-r--r--llvm/test/CodeGen/AArch64/GlobalISel/select-dbg-value.mir36
3 files changed, 32 insertions, 10 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp b/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
index 69ad59ade08..26454c1ef00 100644
--- a/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
@@ -123,7 +123,7 @@ bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) {
// If so, erase it.
if (isTriviallyDead(MI, MRI)) {
DEBUG(dbgs() << "Is dead; erasing.\n");
- MI.eraseFromParent();
+ MI.eraseFromParentAndMarkDBGValuesForRemoval();
continue;
}
diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
index 2e2f519ab2b..606a59680a3 100644
--- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -61,8 +61,8 @@ bool llvm::isTriviallyDead(const MachineInstr &MI,
continue;
unsigned Reg = MO.getReg();
- // Keep Debug uses live: we don't want to have an effect on debug info.
- if (TargetRegisterInfo::isPhysicalRegister(Reg) || !MRI.use_empty(Reg))
+ if (TargetRegisterInfo::isPhysicalRegister(Reg) ||
+ !MRI.use_nodbg_empty(Reg))
return false;
}
return true;
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/select-dbg-value.mir b/llvm/test/CodeGen/AArch64/GlobalISel/select-dbg-value.mir
index cbc7ec88a67..2f36ec8d2aa 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/select-dbg-value.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/select-dbg-value.mir
@@ -3,8 +3,13 @@
--- |
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
- define void @test_dbg_value() !dbg !5 {
- ; Keep the dbg metadata live by referencing it in the IR.
+ define void @test_dbg_value(i32 %a) !dbg !5 {
+ %tmp0 = add i32 %a, %a
+ call void @llvm.dbg.value(metadata i32 %tmp0, i64 0, metadata !7, metadata !9), !dbg !10
+ ret void
+ }
+
+ define void @test_dbg_value_dead(i32 %a) !dbg !5 {
call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !7, metadata !9), !dbg !10
ret void
}
@@ -32,16 +37,33 @@
name: test_dbg_value
legalized: true
regBankSelected: true
-# CHECK: registers:
-# CHECK-NEXT: - { id: 0, class: gpr32all }
+body: |
+ bb.0:
+ liveins: %w0
+ %0:gpr(s32) = COPY %w0
+ %1:gpr(s32) = G_ADD %0, %0
+ %w0 = COPY %1(s32)
+
+ ; CHECK: %0 = COPY %w0
+ ; CHECK-NEXT: %1 = ADDWrr %0, %0
+ ; CHECK-NEXT: %w0 = COPY %1
+ ; CHECK-NEXT: DBG_VALUE debug-use %1, debug-use _, !7, !9, debug-location !10
+
+ DBG_VALUE debug-use %1(s32), debug-use _, !7, !9, debug-location !10
+...
+
+---
+# CHECK-LABEL: name: test_dbg_value_dead
+name: test_dbg_value_dead
+legalized: true
+regBankSelected: true
body: |
bb.0:
liveins: %w0
%0:gpr(s32) = COPY %w0
- ; CHECK: DBG_VALUE debug-use %0, debug-use _, !7, !9, debug-location !10
- ; CHECK: DBG_VALUE _, 0, !7, !9, debug-location !10
+ ; CHECK-NOT: COPY
+ ; CHECK: DBG_VALUE debug-use _, debug-use _, !7, !9, debug-location !10
DBG_VALUE debug-use %0(s32), debug-use _, !7, !9, debug-location !10
- DBG_VALUE _, 0, !7, !9, debug-location !10
...
OpenPOWER on IntegriCloud