[llvm] 2bf4966 - [LiveDebugValues] Do not insert DBG_VALUEs after a MBB terminator

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 13:01:01 PST 2020


Author: Vedant Kumar
Date: 2020-03-03T13:00:52-08:00
New Revision: 2bf496620cbb52f918b24bfa4283f5712fb3b937

URL: https://github.com/llvm/llvm-project/commit/2bf496620cbb52f918b24bfa4283f5712fb3b937
DIFF: https://github.com/llvm/llvm-project/commit/2bf496620cbb52f918b24bfa4283f5712fb3b937.diff

LOG: [LiveDebugValues] Do not insert DBG_VALUEs after a MBB terminator

This fixes a miscompile that happened because a DBG_VALUE interfered
with the MachineOutliner's liveness analysis.

Inserting a DBG_VALUE after a terminator breaks predicates on MBB such
as isReturnBlock(). And the resulting DBG_VALUE cannot be "live".

I plan to introduce a MachineVerifier check for this situation in a
follow up.

rdar://59859175

Testing: check-llvm, LNT build with a stage2 compiler & entry values
enabled

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

Added: 
    

Modified: 
    llvm/lib/CodeGen/LiveDebugValues.cpp
    llvm/test/DebugInfo/MIR/X86/dbginfo-entryvals.mir

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/LiveDebugValues.cpp b/llvm/lib/CodeGen/LiveDebugValues.cpp
index 4d0c2462b7d3..94c5cc58ac1e 100644
--- a/llvm/lib/CodeGen/LiveDebugValues.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues.cpp
@@ -959,6 +959,10 @@ void LiveDebugValues::emitEntryValues(MachineInstr &MI,
                                       VarLocMap &VarLocIDs,
                                       TransferMap &Transfers,
                                       VarLocSet &KillSet) {
+  // Do not insert entry value locations after a terminator.
+  if (MI.isTerminator())
+    return;
+
   for (uint64_t ID : KillSet) {
     LocIndex Idx = LocIndex::fromRawInteger(ID);
     const VarLoc &VL = VarLocIDs[Idx];
@@ -1003,6 +1007,7 @@ void LiveDebugValues::insertTransferDebugPair(
     // Record the new location as an open range, and a postponed transfer
     // inserting a DBG_VALUE for this location.
     OpenRanges.insert(LocId, VL);
+    assert(!MI.isTerminator() && "Cannot insert DBG_VALUE after terminator");
     TransferDebugPair MIP = {&MI, LocId};
     Transfers.push_back(MIP);
   };
@@ -1778,6 +1783,8 @@ bool LiveDebugValues::ExtendRanges(MachineFunction &MF) {
 
   // Add any DBG_VALUE instructions created by location transfers.
   for (auto &TR : Transfers) {
+    assert(!TR.TransferInst->isTerminator() &&
+           "Cannot insert DBG_VALUE after terminator");
     MachineBasicBlock *MBB = TR.TransferInst->getParent();
     const VarLoc &VL = VarLocIDs[TR.LocationID];
     MachineInstr *MI = VL.BuildDbgValue(MF);

diff  --git a/llvm/test/DebugInfo/MIR/X86/dbginfo-entryvals.mir b/llvm/test/DebugInfo/MIR/X86/dbginfo-entryvals.mir
index 5d203029936e..2499d41c7ba1 100644
--- a/llvm/test/DebugInfo/MIR/X86/dbginfo-entryvals.mir
+++ b/llvm/test/DebugInfo/MIR/X86/dbginfo-entryvals.mir
@@ -1,4 +1,4 @@
-# RUN: llc -debug-entry-values -run-pass=livedebugvalues -march=x86-64 -o - %s | FileCheck %s
+# RUN: llc -debug-entry-values -run-pass=livedebugvalues -verify-machineinstrs -march=x86-64 -o - %s | FileCheck %s
 #
 #extern void fn2(int);
 #
@@ -15,7 +15,7 @@
 #  u --;
 #}
 # CHECK: DBG_VALUE $edi, $noreg, !14, !DIExpression(DW_OP_LLVM_entry_value, 1), debug-location {{.*}}
-# CHECK: DBG_VALUE $esi, $noreg, !15, !DIExpression(DW_OP_LLVM_entry_value, 1), debug-location {{.*}}
+# CHECK-NOT: DBG_VALUE $esi, $noreg, !15, !DIExpression(DW_OP_LLVM_entry_value, 1)
 
 --- |
   ; ModuleID = 'test.c'


        


More information about the llvm-commits mailing list