[llvm] [SimplifyCFG] Use hash map to continue hoisting the common instructions (PR #78615)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 20 08:35:49 PDT 2024


================
@@ -1739,18 +1840,44 @@ bool SimplifyCFGOpt::hoistCommonCodeFromSuccessors(BasicBlock *BB,
         // leave any that were not hoisted behind (by calling moveBefore
         // rather than moveBeforePreserving).
         I1->moveBefore(TI);
-        for (auto &SuccIter : OtherSuccIterRange) {
-          Instruction *I2 = &*SuccIter++;
+        for (auto *I2 : OtherInsts) {
           assert(I2 != I1);
-          if (!I2->use_empty())
+          // Update hashcode of all instructions using I2
+          if (!I2->use_empty()) {
+            SmallVector<llvm::Instruction *, 8> PrevUsers;
+            // Once the uses of I1 are replaced, the hash value computed for
+            // those users are not valid anymore so we gather users and then
+            // recompute the hash codes for them. We need to do this only for
+            // the instructions located in the same block as I2 because we
+            // initially only hashed those instructions.
+            for (auto *user : I2->users()) {
----------------
nikic wrote:

```suggestion
            for (User *U : I2->users()) {
```

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


More information about the llvm-commits mailing list