[llvm] [CodeExtractor] Optimize PHI incoming value removal using reverse iteration (NFC) (PR #171956)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 14 22:00:45 PST 2025
int-zjt wrote:
> Same question here. I believe this should be using removeIncomingValueIf() instead.
Apologies, I got my replies crossed between two patches. This is actually the place I intended to discuss regarding the `addIncoming` side effect.
As mentioned, using `removeIncomingValueIf` here would require embedding the move logic into the lambda:
```cpp
PN->removeIncomingValueIf([&](unsigned i) {
if (Blocks.count(PN->getIncomingBlock(i))) {
// Side effect: moving to NewPN
NewPN->addIncoming(PN->getIncomingValue(i), PN->getIncomingBlock(i));
return true;
}
return false;
});
```
I feel the explicit loop makes the 'move' semantics clearer than hiding it inside a removal predicate. What do you think?
https://github.com/llvm/llvm-project/pull/171956
More information about the llvm-commits
mailing list