[llvm] [SimplifyCFG] Use hash map to continue hoisting the common instructions (PR #78615)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 19 13:25:33 PDT 2024
================
@@ -1608,16 +1622,42 @@ bool SimplifyCFGOpt::hoistCommonCodeFromSuccessors(BasicBlock *BB,
auto *TI = BB->getTerminator();
+ SmallVector<BasicBlock *, 8> SuccessorBBs;
+ for (auto *Succ : successors(BB)) {
+ // If we find an unreachable instruction at the beginning of a basic block,
+ // we can still hoist instructions from the rest of the basic blocks.
+ if (isa<UnreachableInst>(Succ->getFirstNonPHIOrDbg()))
+ continue;
+ SuccessorBBs.push_back(Succ);
+ }
+
+ // Find the smallest BB because we always want to iterate over instructions
+ // of the smallest Successor.
+ auto *SmallestBBPos =
+ std::min_element(SuccessorBBs.begin(), SuccessorBBs.end(),
+ [](BasicBlock *BB1, BasicBlock *BB2) {
+ return BB1->size() < BB2->size();
+ });
+
+ std::iter_swap(SuccessorBBs.begin(), SmallestBBPos);
+ BasicBlock *SmallestBB = *SmallestBBPos;
+
+ if (SmallestBB->size() > BBSizeHoistLimit)
----------------
nikic wrote:
These size() calls should be sizeWithoutDebug(), otherwise the debug invariance property will be violated.
https://github.com/llvm/llvm-project/pull/78615
More information about the llvm-commits
mailing list