[llvm] [CloneFunciton] Optimize PHI incoming value removal using reverse iteration (NFC) (PR #171955)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 11 19:50:28 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/171955.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/Utils/CloneFunction.cpp (+4-5)
``````````diff
diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp
index 32924e7b69fdc..1d0244c54a282 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -35,6 +35,7 @@
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
+#include <cstdint>
#include <map>
#include <optional>
using namespace llvm;
@@ -785,7 +786,7 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
++phino) {
OPN = PHIToResolve[phino];
PHINode *PN = cast<PHINode>(VMap[OPN]);
- for (unsigned pred = 0, e = NumPreds; pred != e; ++pred) {
+ for (int64_t pred = NumPreds - 1; pred >= 0; --pred) {
Value *V = VMap.lookup(PN->getIncomingBlock(pred));
if (BasicBlock *MappedBlock = cast_or_null<BasicBlock>(V)) {
Value *InVal =
@@ -794,11 +795,9 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
assert(InVal && "Unknown input value?");
PN->setIncomingValue(pred, InVal);
PN->setIncomingBlock(pred, MappedBlock);
- } else {
- PN->removeIncomingValue(pred, false);
- --pred; // Revisit the next entry.
- --e;
+ continue;
}
+ PN->removeIncomingValue(pred, false);
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/171955
More information about the llvm-commits
mailing list