https://github.com/lukel97 updated 
https://github.com/llvm/llvm-project/pull/238023

>From 0a8d310235f228f34339548545b0c80fee61884a Mon Sep 17 00:00:00 2001
From: Luke Lau <[email protected]>
Date: Sat, 31 Oct 2026 17:28:02 +0800
Subject: [PATCH] [VPlan] Lower MaskedCond earlier in the predicator. NFC

A MaskedCond is used to logically-and some condition with the current block in 
mask.

It's currently lowered in convertToConcreteRecipes but we can just do it 
earlier in VPlanPredicator, which removes the need for the separate fold in 
simplifyRecipe. It also enables more logical-and simplifications earlier on.
---
 llvm/lib/Transforms/Vectorize/VPlanLowering.cpp   | 11 -----------
 llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp | 14 +++++++++++++-
 llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp |  5 -----
 3 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlanLowering.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanLowering.cpp
index 47d3b722ac927..372d124c2ff71 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanLowering.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanLowering.cpp
@@ -662,17 +662,6 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan 
&Plan) {
         continue;
       }
 
-      // Lower MaskedCond with block mask to LogicalAnd.
-      if (match(&R, m_VPInstruction<VPInstruction::MaskedCond>())) {
-        auto *VPI = cast<VPInstruction>(&R);
-        assert(VPI->isMasked() &&
-               "Unmasked MaskedCond should be simplified earlier");
-        VPI->replaceAllUsesWith(Builder.createNaryOp(
-            VPInstruction::LogicalAnd, {VPI->getMask(), VPI->getOperand(0)}));
-        VPI->eraseFromParent();
-        continue;
-      }
-
       // Lower CanonicalIVIncrementForPart to plain Add.
       if (match(
               &R,
diff --git a/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp
index 58c00e3b4196e..953bf97f2bf9d 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanPredicator.cpp
@@ -489,7 +489,19 @@ void VPPredicator::run() {
 
     VPValue *BlockMask = getBlockInMask(VPBB);
     // Mask all VPInstructions in the block.
-    for (VPInstruction &VPI : make_isa_range<VPInstruction>(*VPBB)) {
+    for (VPInstruction &VPI :
+         make_early_inc_range(make_isa_range<VPInstruction>(*VPBB))) {
+      // Lower MaskedCond to logical-and(block-in-mask, x).
+      if (VPI.getOpcode() == VPInstruction::MaskedCond) {
+        VPValue *Cond = VPI.getOperand(0);
+        if (BlockMask)
+          Cond = VPBuilder(&VPI).createLogicalAnd(BlockMask, Cond,
+                                                  VPI.getDebugLoc());
+        VPI.replaceAllUsesWith(Cond);
+        VPI.eraseFromParent();
+        continue;
+      }
+
       if (BlockMask)
         VPI.addMask(BlockMask);
 
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index a43360f33c837..280346698099e 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -1309,11 +1309,6 @@ static VPValue *simplifyRecipe(VPlan &Plan, 
VPSingleDefRecipe *Def) {
       A->getScalarType() == Def->getScalarType())
     return A;
 
-  // Simplify MaskedCond with no block mask to its single operand.
-  if (match(Def, m_VPInstruction<VPInstruction::MaskedCond>()) &&
-      !cast<VPInstruction>(Def)->isMasked())
-    return Def->getOperand(0);
-
   // Look through ExtractLastLane.
   if (match(Def, m_ExtractLastLane(m_VPValue(A)))) {
     if (match(A, m_BuildVector())) {

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to