[PATCH] D71480: [BasicBlockUtils] Fix dbg.value elimination problem in MergeBlockIntoPredecessor

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 13 10:24:52 PST 2019


bjope created this revision.
bjope added reviewers: aprantl, jmorse, vsk.
Herald added subscribers: hiraditya, jholewinski.
Herald added a project: LLVM.
bjope added parent revisions: D71479: [LoopRotate] Add test case to show dbg value problem, D71478: [BasicBlockUtils] Add utility to remove redundant dbg.value instrs.
bjope marked 2 inline comments as done.
bjope added inline comments.


================
Comment at: llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll:47
+; CHECK-NOT: //DEBUG_VALUE: baz:z
+; CHECK: //DEBUG_VALUE: baz:z <- undef
 ; CHECK: .loc [[CU2]] 10 0
----------------
It should be noticed that this mapping of baz:z to undef was present in the baseline (but not covered by the checks). Now I verify that we get a single DEBUG_VALUE for baz:z here, and that happens to be the last one (i.e. undef).


================
Comment at: llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue-inlined.ll:11
 ; CHECK-NEXT:  call void @llvm.dbg.value(metadata i64 %vala, metadata [[MD:![0-9]*]]
-; CHECK-NEXT:  call void @llvm.dbg.value(metadata i64 %vala, metadata [[MD]]
 ; CHECK-NEXT:  %valbmasked = and i64 %vala, 1
----------------
Both of these had same inlineAt, so the first one was redundant. Not sure if this makes the test case no longer verifying what it was supposed to verify.


In commit d60f34c20a2f31335c8d5626e (llvm-svn 317128,
PR35113) MergeBlockIntoPredecessor was changed into
discarding some dbg.value intrinsics referring to
PHI values, post-splice due to loop rotation.

That elimination of dbg.value intrinsics did not
consider which dbg.value to keep depending on the
context (e.g. if the variable is changing it's value
several times inside the basic block).

In the past that hasn't been such a big problem since
CodeGenPrepare::placeDbgValues has moved the dbg.value
to be next to the PHI node anyway. But after commit
00e238896cd8ad3a7d7 <https://reviews.llvm.org/rG00e238896cd8ad3a7d715b8fb5f12a2e60af8a6f> CodeGenPrepare isn't doing that
any longer, so we need to be more careful when avoiding
duplicate dbg.value intrinsics in MergeBlockIntoPredecessor.

This patch replaces the code that tried to avoid duplicate
dbg.values by using the RemoveRedundantDbgInstrs helper.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71480

Files:
  llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
  llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll
  llvm/test/Transforms/LoopRotate/dbg-value-duplicates-2.ll
  llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue-inlined.ll


Index: llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue-inlined.ll
===================================================================
--- llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue-inlined.ll
+++ llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue-inlined.ll
@@ -8,7 +8,6 @@
 
 ; CHECK:  %vala = load i64, i64* %ptr
 ; CHECK-NEXT:  call void @llvm.dbg.value(metadata i64 %vala, metadata [[MD:![0-9]*]]
-; CHECK-NEXT:  call void @llvm.dbg.value(metadata i64 %vala, metadata [[MD]]
 ; CHECK-NEXT:  %valbmasked = and i64 %vala, 1
 
 a:                                              ; preds = %init
Index: llvm/test/Transforms/LoopRotate/dbg-value-duplicates-2.ll
===================================================================
--- llvm/test/Transforms/LoopRotate/dbg-value-duplicates-2.ll
+++ llvm/test/Transforms/LoopRotate/dbg-value-duplicates-2.ll
@@ -11,12 +11,10 @@
 ; CHECK-NEXT:    call void @llvm.dbg.value(metadata i16 [[TMP1]], metadata !12, metadata !DIExpression()), !dbg !13
 ; CHECK-NEXT:    [[TMP4:%.*]] = call i16 @wibble(i16 [[TMP1]]), !dbg !14
 ; CHECK-NEXT:    [[TMP5]] = add nsw i16 [[TMP4]], [[TMP1]], !dbg !14
+; CHECK-NEXT:    call void @llvm.dbg.value(metadata i16 [[TMP5]], metadata !12, metadata !DIExpression()), !dbg !13
 ; CHECK-NEXT:    [[TMP6:%.*]] = call i16 @wibble(i16 [[TMP4]]), !dbg !14
 ; CHECK-NEXT:    [[TMP7:%.*]] = mul nsw i16 [[TMP6]], 3, !dbg !14
 ; CHECK-NEXT:    [[TMP8:%.*]] = call i16 @wibble(i16 [[TMP7]]), !dbg !14
-; BUG: This dbg.value is expected to be placed directly after the add above.
-;      Otherwise variable "x" (!12) won't be described as having the correct value at the call to wibble just after the add.
-; CHECK-NEXT:    call void @llvm.dbg.value(metadata i16 [[TMP5]], metadata !12, metadata !DIExpression()), !dbg !13
 ; CHECK-NEXT:    [[TMP2:%.*]] = icmp slt i16 [[TMP5]], 17, !dbg !14
 ; CHECK-NEXT:    br i1 [[TMP2]], label [[BB2]], label [[BB3:%.*]], !dbg !14
 ; CHECK:       bb3:
Index: llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll
===================================================================
--- llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll
+++ llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll
@@ -43,8 +43,8 @@
 ; CHECK: .loc [[CU2:[0-9]+]] 6 0
 ; CHECK: Lfunc_begin1:
 ; CHECK: .loc [[CU2]] 6 0
-; CHECK: //DEBUG_VALUE: baz:z <- {{[0-9]+}}
-; CHECK: //DEBUG_VALUE: baz:z <- {{[0-9]+}}
+; CHECK-NOT: //DEBUG_VALUE: baz:z
+; CHECK: //DEBUG_VALUE: baz:z <- undef
 ; CHECK: .loc [[CU2]] 10 0
 ; CHECK: ret;
 ; CHECK: }
Index: llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -284,20 +284,10 @@
   // Add unreachable to now empty BB.
   new UnreachableInst(BB->getContext(), BB);
 
-  // Eliminate duplicate dbg.values describing the entry PHI node post-splice.
-  for (auto Incoming : IncomingValues) {
-    if (isa<Instruction>(*Incoming)) {
-      SmallVector<DbgValueInst *, 2> DbgValues;
-      SmallDenseSet<std::pair<DILocalVariable *, DIExpression *>, 2>
-          DbgValueSet;
-      llvm::findDbgValues(DbgValues, Incoming);
-      for (auto &DVI : DbgValues) {
-        auto R = DbgValueSet.insert({DVI->getVariable(), DVI->getExpression()});
-        if (!R.second)
-          DVI->eraseFromParent();
-      }
-    }
-  }
+  // Eliminate duplicate/redundant dbg.values. This seems to be a good place to
+  // do that sine we might end up with redundant dbg.values describing the entry
+  // PHI node post-splice.
+  RemoveRedundantDbgInstrs(PredBB);
 
   // Inherit predecessors name if it exists.
   if (!PredBB->hasName())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71480.233831.patch
Type: text/x-patch
Size: 3683 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191213/ee4689bc/attachment.bin>


More information about the llvm-commits mailing list