[llvm] [NFC][LoopVectorize] Make replaceVPBBWithIRVPBB more efficient (PR #111514)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 13 12:19:42 PDT 2024


================
@@ -556,6 +556,26 @@ class VPBlockBase {
     return getEnclosingBlockWithPredecessors()->getSinglePredecessor();
   }
 
+  /// This function replaces one predecessor with another, useful when
+  /// trying to replace an old block in the CFG with a new one.
+  void replacePredecessor(VPBlockBase *Old, VPBlockBase *New) {
+    auto I = find(Predecessors, Old);
+    assert(I != Predecessors.end());
+    assert(Old->getParent() == New->getParent() &&
+           "replaced predecessor must have the same parent");
+    *I = New;
----------------
fhahn wrote:

I think this may  leaves `Old` in an invalid state, as we remove it from the list of predecessors here, but don't remove `this` from the `Successors` of `Old`. Can we also remove it from there? Otherwise the callers of the API must either remove the node itself  or completely delete the block

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


More information about the llvm-commits mailing list