[llvm] 94b2617 - [VPlan] Remove VPIRPhis in exit blocks when deleting scalar loop BBs.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 1 14:03:02 PDT 2025


Author: Florian Hahn
Date: 2025-10-01T22:01:23+01:00
New Revision: 94b2617590c11b372a2161ccdfe52ecd73d58ec1

URL: https://github.com/llvm/llvm-project/commit/94b2617590c11b372a2161ccdfe52ecd73d58ec1
DIFF: https://github.com/llvm/llvm-project/commit/94b2617590c11b372a2161ccdfe52ecd73d58ec1.diff

LOG: [VPlan] Remove VPIRPhis in exit blocks when deleting scalar loop BBs.

DeleteDeadBlocks will remove single-entry phis. Remove them from the exit
VPIRBBs in VPlan as well, otherwise we would retain references to deleted
IR instructions.

Fixes MSan failures after 8907b6d39
https://lab.llvm.org/buildbot/#/builders/164/builds/14013

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/VPlan.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index ffd2e59938510..02eb6375aac41 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -978,6 +978,16 @@ void VPlan::execute(VPTransformState *State) {
 
   // If the original loop is unreachable, delete it and all its blocks.
   if (!ScalarPhVPBB->hasPredecessors()) {
+    // DeleteDeadBlocks will remove single-entry phis. Remove them from the exit
+    // VPIRBBs in VPlan as well, otherwise we would retain references to deleted
+    // IR instructions.
+    for (VPIRBasicBlock *EB : getExitBlocks()) {
+      for (VPRecipeBase &R : make_early_inc_range(EB->phis())) {
+        if (R.getNumOperands() == 1)
+          R.eraseFromParent();
+      }
+    }
+
     Loop *OrigLoop =
         State->LI->getLoopFor(getScalarHeader()->getIRBasicBlock());
     auto Blocks = OrigLoop->getBlocksVector();


        


More information about the llvm-commits mailing list