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

Quentin Dian via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 21 17:45:38 PST 2024


================
@@ -1671,25 +1671,51 @@ bool SimplifyCFGOpt::hoistCommonCodeFromSuccessors(BasicBlock *BB,
 
   bool Changed = false;
   auto *SuccIterPairBegin = SuccIterPairs.begin();
-  SuccIterPairBegin++;
+  ++SuccIterPairBegin;
+  auto BBItrPair = *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) {
+  DenseMap<llvm::hash_code, SmallVector<Instruction *, 2>> OtherSuccessorsHash;
+  DenseMap<Instruction *, unsigned> InstToSkipFlag;
+
+  unsigned skipFlag = 0;
+  Instruction *I = nullptr;
+  do {
+    I = &*BBItrPair.first;
+    auto HashValue = getHash(I);
+    skipFlag |= skippedInstrFlags(I);
+    // For the first successor we created hashmap for, put all instructions
+    // in the hashmap execept for the ones that have the same hash as some
+    // previous instruction in that BB.
+    if (OtherSuccessorsHash.find(HashValue) == OtherSuccessorsHash.end()) {
+      SmallVector<Instruction *, 2> vec{I};
----------------
DianQK wrote:

Maybe we need to raise this value.

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


More information about the llvm-commits mailing list