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

Quentin Dian via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 6 17:23:21 PST 2024


================
@@ -1589,80 +1610,121 @@ bool SimplifyCFGOpt::hoistCommonCodeFromSuccessors(BasicBlock *BB,
   }
 
   bool Changed = false;
+  auto *SuccIterPairBegin = SuccIterPairs.begin();
+  SuccIterPairBegin++;
+  auto OtherSuccIterPairRange =
+      iterator_range(SuccIterPairBegin, SuccIterPairs.end());
+  auto OtherSuccIterRange = make_first_range(OtherSuccIterPairRange);
+  using InstrFlagPair = std::pair<Instruction *, unsigned>;
+  SmallVector<DenseMap<llvm::hash_code, InstrFlagPair>, 2> OtherSuccessorsHash;
+
+  for (auto BBItrPair : OtherSuccIterRange) {
+    // Fill the hashmap for every other successor
+    DenseMap<llvm::hash_code, InstrFlagPair> hashMap;
----------------
DianQK wrote:

After switching to a vector, if we find here that the number of instructions is less than the number of successors, we can just skip it. See https://github.com/llvm/llvm-project/pull/78615/files#diff-f1d6bccbcc778d09cdbe3f6f9d215299c9eaf9c9af6f66dbe6c90c4ad8e53904R1717-R1724.

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


More information about the llvm-commits mailing list