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

Quentin Dian via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 1 22:21:25 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;
+    unsigned skipFlag = 0;
+    Instruction *I = nullptr;
+    do {
+      I = &*BBItrPair;
+      skipFlag |= skippedInstrFlags(I);
----------------
DianQK wrote:

> Actually yes, because I keep track two SkipFlags for each successor, one created for every instruction when I fill the hashmap, the other one created for that successor and gets updated while I'm iterating through first successor instructions (same as previous approach). The second one will be valid as long as I have not hoisted two instructions that are not in the same level.

When hoisting a set of instructions with different levels, should we update it?

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


More information about the llvm-commits mailing list