[llvm] [SimplifyCFG] Fix hoisting problem in SimplifyCFG (PR #78615)

Quentin Dian via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 21 17:30:50 PST 2024


================
@@ -1552,10 +1562,21 @@ bool SimplifyCFGOpt::hoistCommonCodeFromSuccessors(BasicBlock *BB,
 
   auto *TI = BB->getTerminator();
 
+  SmallVector<BasicBlock *> SuccessorBlocks;
+  for (auto *Succ : successors(BB))
+    SuccessorBlocks.push_back(Succ);
+
+  // Sort successor blocks based on the number of instructions.
+  // This is because we always want to iterate over instructions
+  // of the smallest block.
+  llvm::stable_sort(SuccessorBlocks, [](BasicBlock *BB1, BasicBlock *BB2) {
----------------
DianQK wrote:

Maybe you don't need to sort it. I think we just need to find the smallest BB.

https://github.com/llvm/llvm-project/pull/78615


More information about the llvm-commits mailing list