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

via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 13:51:30 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;
----------------
RouzbehPaktinat wrote:

Thanks, I got your point.
With the current implantation we might miss some coroner cases as you mentioned however, it will happen rarely.
I'll be happy to make the changes you suggested to cover those cases but I guess it might result in some compile time overhead. 
If I have more than one instruction from a BB in a vector, then I need to go over each instruction in that vector and decide which ones should be hoisted. If all those instructions are identical, this decision and checks it requires might become a bit expensive however, if you think it is necessary, I'll be glad to implement that.

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


More information about the llvm-commits mailing list