[llvm] [SSAUpdater] Avoid scanning basic blocks to find instruction order. (PR #123803)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 21 12:47:20 PST 2025


================
@@ -432,27 +432,27 @@ void LoadAndStorePromoter::run(const SmallVectorImpl<Instruction *> &Insts) {
       }
     }
 
-    // If so, we can queue them all as live in loads.  We don't have an
-    // efficient way to tell which on is first in the block and don't want to
-    // scan large blocks, so just add all loads as live ins.
+    // If so, we can queue them all as live in loads.
     if (!HasStore) {
       for (Instruction *I : BlockUses)
         LiveInLoads.push_back(cast<LoadInst>(I));
       BlockUses.clear();
       continue;
     }
 
+    // Sort all of the interesting instructions in the block so that we don't
+    // have to scan a large block just to find a few instructions.
+    std::sort(BlockUses.begin(), BlockUses.end(),
+              [](Instruction *A, Instruction *B) { return A->comesBefore(B); });
----------------
nikic wrote:

```suggestion
    llvm::sort(BlockUses,
               [](Instruction *A, Instruction *B) { return A->comesBefore(B); });
```

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


More information about the llvm-commits mailing list