[PATCH] D91511: [JumpThreading] Call eraseBlock when folding a conditional branch
Kazu Hirata via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 15 18:12:07 PST 2020
kazu created this revision.
kazu added reviewers: yrouban, MaskRay.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
kazu requested review of this revision.
This patch teaches the jump threading pass to call BPI->eraseBlock
when it folds a conditional branch.
Without this patch, BranchProbabilityInfo could end up with stale edge
probabilities for the basic block containing the conditional branch --
one edge probability with less than 1.0 and the other for a removed
edge.
This patch is one of the steps before we can safely re-apply D91017 <https://reviews.llvm.org/D91017>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91511
Files:
llvm/lib/Analysis/BranchProbabilityInfo.cpp
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/test/Transforms/JumpThreading/thread-prob-2.ll
Index: llvm/test/Transforms/JumpThreading/thread-prob-2.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/JumpThreading/thread-prob-2.ll
@@ -0,0 +1,22 @@
+; RUN: opt -debug-only=branch-prob -jump-threading -S %s 2>&1 | FileCheck %s
+; REQUIRES: asserts
+
+; Make sure that we clear edge probabilities for bb.cond as we fold
+; the conditional branch in it.
+
+define i32 @foo(i1 %cond) !prof !0 {
+bb.entry:
+ br i1 %cond, label %bb.31, label %bb.cond
+
+bb.cond:
+ br i1 %cond, label %bb.31, label %bb.12
+; CHECK: eraseBlock bb.cond
+
+bb.31:
+ ret i32 31
+
+bb.12:
+ ret i32 12
+}
+
+!0 = !{!"function_entry_count", i64 0}
Index: llvm/lib/Transforms/Scalar/JumpThreading.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -1697,6 +1697,8 @@
BranchInst::Create(OnlyDest, Term);
Term->eraseFromParent();
DTU->applyUpdatesPermissive(Updates);
+ if (HasProfileData)
+ BPI->eraseBlock(BB);
// If the condition is now dead due to the removal of the old terminator,
// erase it.
Index: llvm/lib/Analysis/BranchProbabilityInfo.cpp
===================================================================
--- llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -1183,6 +1183,8 @@
}
void BranchProbabilityInfo::eraseBlock(const BasicBlock *BB) {
+ LLVM_DEBUG(dbgs() << "eraseBlock " << BB->getName() << "\n");
+
// Note that we cannot use successors of BB because the terminator of BB may
// have changed when eraseBlock is called as a BasicBlockCallbackVH callback.
// Instead we remove prob data for the block by iterating successors by their
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91511.305399.patch
Type: text/x-patch
Size: 1825 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201116/406f7be2/attachment.bin>
More information about the llvm-commits
mailing list