[llvm] [LV][RFC] Generating conditional VPBB that will be skip when the mask is inactive in VPlan. (PR #141900)
Ashutosh Nema via llvm-commits
llvm-commits at lists.llvm.org
Mon May 25 03:46:10 PDT 2026
================
@@ -6494,3 +6518,165 @@ void VPlanTransforms::makeScalarizationDecisions(VPlan &Plan, VFRange &Range) {
}
}
}
+
+void VPlanTransforms::optimizeConditionalVPBB(VPlan &Plan) {
+ VPDominatorTree VPDT(Plan);
+
+ VPValue *HeaderMask = vputils::findHeaderMask(Plan);
+
+ // Get the mask from the store recipes.
+ auto GetMask = [&HeaderMask](VPRecipeBase &R) -> VPValue * {
+ using namespace llvm::VPlanPatternMatch;
+ if (!isa<VPWidenStoreRecipe>(R))
+ return nullptr;
+ VPValue *OrigMask = cast<VPWidenMemoryRecipe>(R).getMask();
+ if (!OrigMask || OrigMask == HeaderMask)
+ return nullptr;
+
+ return OrigMask;
+ };
+
+ // First, collect all masked stores.
+ SmallVector<std::pair<VPRecipeBase *, VPValue *>> MaskedStores;
+ ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<VPBlockBase *>> RPOT(
+ Plan.getEntry());
+ for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
+ for (VPRecipeBase &R : *VPBB) {
+ if (VPValue *Mask = GetMask(R))
+ MaskedStores.emplace_back(&R, Mask);
+ }
+ }
+
+ if (MaskedStores.empty())
----------------
nema-ashutosh wrote:
This limits the transformation to store-rooted trees only.
Conditional blocks that contain only expensive computations i.e. FP math, masked loads, gathers, replicated recipes, or interleave groups won't be considered.
For example, a loop like:
if (cond[i]) {
temp += sqrt(A[i]) * log(B[C[i]]);
}
Such limitations are not in PR #197423
https://github.com/llvm/llvm-project/pull/141900
More information about the llvm-commits
mailing list