From 7d4dc9f097d83c5ff12a8a64344dab9e6bd2e547 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Tue, 20 Sep 2022 20:14:11 -0700 Subject: [PATCH] JIT: improve scalability of optReachable Use a bit vector to track the visited blocks. This scales much better than using the per-block visited flags. Fixes #44341. --- src/coreclr/jit/compiler.h | 2 ++ src/coreclr/jit/redundantbranchopts.cpp | 23 ++++++++++++----------- src/tests/issues.targets | 3 --- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 3d284ecf96a27..8218b606194fb 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -6980,6 +6980,8 @@ class Compiler bool optRedundantBranch(BasicBlock* const block); bool optJumpThread(BasicBlock* const block, BasicBlock* const domBlock, bool domIsSameRelop); bool optReachable(BasicBlock* const fromBlock, BasicBlock* const toBlock, BasicBlock* const excludedBlock); + BitVecTraits* optReachableBitVecTraits; + BitVec optReachableBitVec; void optRelopImpliesRelop(RelopImplicationInfo* rii); /************************************************************************** diff --git a/src/coreclr/jit/redundantbranchopts.cpp b/src/coreclr/jit/redundantbranchopts.cpp index 4b65d006af5d0..a333cad69aca7 100644 --- a/src/coreclr/jit/redundantbranchopts.cpp +++ b/src/coreclr/jit/redundantbranchopts.cpp @@ -74,16 +74,10 @@ PhaseStatus Compiler::optRedundantBranches() } }; + optReachableBitVecTraits = nullptr; OptRedundantBranchesDomTreeVisitor visitor(this); visitor.WalkTree(); - // Reset visited flags, in case we set any. - // - for (BasicBlock* const block : Blocks()) - { - block->bbFlags &= ~BBF_VISITED; - } - #if DEBUG if (verbose && visitor.madeChanges) { @@ -1593,9 +1587,15 @@ bool Compiler::optReachable(BasicBlock* const fromBlock, BasicBlock* const toBlo return true; } - for (BasicBlock* const block : Blocks()) + if (optReachableBitVecTraits == nullptr) { - block->bbFlags &= ~BBF_VISITED; + optReachableBitVecTraits = new (this, CMK_Reachability) BitVecTraits(fgBBNumMax + 1, this); + optReachableBitVec = BitVecOps::MakeEmpty(optReachableBitVecTraits); + } + else + { + assert(BitVecTraits::GetSize(optReachableBitVecTraits) == fgBBNumMax + 1); + BitVecOps::ClearD(optReachableBitVecTraits, optReachableBitVec); } ArrayStack stack(getAllocator(CMK_Reachability)); @@ -1604,7 +1604,6 @@ bool Compiler::optReachable(BasicBlock* const fromBlock, BasicBlock* const toBlo while (!stack.Empty()) { BasicBlock* const nextBlock = stack.Pop(); - nextBlock->bbFlags |= BBF_VISITED; assert(nextBlock != toBlock); if (nextBlock == excludedBlock) @@ -1619,11 +1618,13 @@ bool Compiler::optReachable(BasicBlock* const fromBlock, BasicBlock* const toBlo return true; } - if ((succ->bbFlags & BBF_VISITED) != 0) + if (BitVecOps::IsMember(optReachableBitVecTraits, optReachableBitVec, succ->bbNum)) { continue; } + BitVecOps::AddElemD(optReachableBitVecTraits, optReachableBitVec, succ->bbNum); + stack.Push(succ); } } diff --git a/src/tests/issues.targets b/src/tests/issues.targets index 8653f6e609172..4d8386639b352 100644 --- a/src/tests/issues.targets +++ b/src/tests/issues.targets @@ -51,9 +51,6 @@ https://github.com/dotnet/runtime/issues/10888 https://github.com/dotnet/runtime/issues/11823 - - https://github.com/dotnet/runtime/issues/44341 - https://github.com/dotnet/runtime/issues/55966