[llvm] [VPlan] Move tail folding out of VPlanPredicator. NFC (PR #176143)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 23 09:19:57 PST 2026


================
@@ -232,15 +205,22 @@ void VPPredicator::createSwitchEdgeMasks(VPInstruction *SI) {
 void VPPredicator::convertPhisToBlends(VPBasicBlock *VPBB) {
   SmallVector<VPPhi *> Phis;
   for (VPRecipeBase &R : VPBB->phis())
-    Phis.push_back(cast<VPPhi>(&R));
+    if (auto *PhiR = dyn_cast<VPPhi>(&R))
+      Phis.push_back(PhiR);
   for (VPPhi *PhiR : Phis) {
     // The non-header Phi is converted into a Blend recipe below,
     // so we don't have to worry about the insertion order and we can just use
     // the builder. At this point we generate the predication tree. There may
     // be duplications since this is a simple recursive scan, but future
     // optimizations will clean it up.
 
-    if (all_equal(PhiR->incoming_values())) {
+    auto NotPoison = [&](VPValue *V) {
+      // Don't remove poison from phis from the original loop.
+      return PhiR->getUnderlyingValue() || !isa<VPIRValue>(V) ||
+             !isa<PoisonValue>(cast<VPIRValue>(V)->getValue());
+    };
----------------
lukel97 wrote:

Is it #171851, and the successor https://github.com/llvm/llvm-project/pull/150369? Those patches essentially do the code snippet above.

But for this patch at least we need this special casing, and we don't yet have a simplification for a select with a poison value. And we also don't run simplification this early on yet, so we would need to manually call it here. But all for another patch.

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


More information about the llvm-commits mailing list