[PATCH] D88928: [Utils] Skip RemoveRedundantDbgInstrs in MergeBlockIntoPredecessor (PR47746)
Vedant Kumar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 6 14:33:05 PDT 2020
vsk created this revision.
vsk added reviewers: fhahn, bjope, aprantl, jmorse.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
vsk requested review of this revision.
This patch is for discussion purposes, see llvm.org/PR47746.
---
This patch changes MergeBlockIntoPredecessor to skip the call to
RemoveRedundantDbgInstrs, in effect partially reverting D71480 <https://reviews.llvm.org/D71480> due to
some compile-time issues spotted in LoopUnroll and SimplifyCFG.
The call to RemoveRedundantDbgInstrs appears to have changed the
worst-case behavior of the merging utility. Loosely speaking, it seems
to have gone from O(#phis) to O(#insts).
It might not be possible to mitigate this by scanning a block to
determine whether there are any debug intrinsics to remove, since such a
scan costs O(#insts).
So: skip the call to RemoveRedundantDbgInstrs. There's surprisingly
little fallout from this, and most of it can be addressed by doing
RemoveRedundantDbgInstrs later. The exception is (the block-local
version of) SimplifyCFG, where it might just be too expensive to call
RemoveRedundantDbgInstrs.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D88928
Files:
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
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,6 +8,7 @@
; 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
@@ -26,6 +27,8 @@
ret i64 %retv
}
+; CHECK: [[MD]] = !DILocalVariable(name: "var"
+
; Function Attrs: nounwind readnone speculatable
declare void @llvm.dbg.value(metadata, metadata, metadata) #0
Index: llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
+++ llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
@@ -578,7 +578,10 @@
// connected by an unconditional branch. This is just a cleanup so the
// emitted code isn't too gross in this common case.
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
- MergeBlockIntoPredecessor(OrigHeader, &DTU, LI, MSSAU);
+ BasicBlock *PredBB = OrigHeader->getUniquePredecessor();
+ bool DidMerge = MergeBlockIntoPredecessor(OrigHeader, &DTU, LI, MSSAU);
+ if (DidMerge)
+ RemoveRedundantDbgInstrs(PredBB);
if (MSSAU && VerifyMemorySSA)
MSSAU->getMemorySSA()->verifyMemorySSA();
Index: llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -285,11 +285,6 @@
// Add unreachable to now empty BB.
new UnreachableInst(BB->getContext(), BB);
- // Eliminate duplicate/redundant dbg.values. This seems to be a good place to
- // do that since 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())
PredBB->takeName(BB);
Index: llvm/lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -655,6 +655,7 @@
for (auto &Block : llvm::make_range(std::next(F.begin()), F.end()))
Blocks.push_back(&Block);
+ SmallSet<WeakTrackingVH, 16> Preds;
for (auto &Block : Blocks) {
auto *BB = cast_or_null<BasicBlock>(Block);
if (!BB)
@@ -673,8 +674,16 @@
// Merge BB into SinglePred and delete it.
MergeBlockIntoPredecessor(BB);
+ Preds.insert(SinglePred);
}
}
+
+ // (Repeatedly) merging blocks into their predecessors can create redundant
+ // debug intrinsics.
+ for (auto &Pred : Preds)
+ if (auto *BB = cast_or_null<BasicBlock>(Pred))
+ RemoveRedundantDbgInstrs(BB);
+
return Changed;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88928.296547.patch
Type: text/x-patch
Size: 3110 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201006/068e9805/attachment.bin>
More information about the llvm-commits
mailing list