[llvm] [CodeExtractor] Optimize PHI incoming value removal using reverse iteration (NFC) (PR #171956)

via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 11 19:50:59 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: None (int-zjt)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/171956.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/Utils/CodeExtractor.cpp (+1-1) 


``````````diff
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index 0ca1fa2425a53..caf3309cb4c92 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -749,7 +749,7 @@ void CodeExtractor::severSplitPHINodesOfEntry(BasicBlock *&Header) {
 
       // Loop over all of the incoming value in PN, moving them to NewPN if they
       // are from the extracted region.
-      for (unsigned i = 0; i != PN->getNumIncomingValues(); ++i) {
+      for (int i = PN->getNumIncomingValues() - 1; i >= 0; --i) {
         if (Blocks.count(PN->getIncomingBlock(i))) {
           NewPN->addIncoming(PN->getIncomingValue(i), PN->getIncomingBlock(i));
           PN->removeIncomingValue(i);

``````````

</details>


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


More information about the llvm-commits mailing list