[llvm] [VPlan] Constant-fold ActiveLaneMask intrinsics (PR #208852)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 14 11:54:07 PDT 2026
================
@@ -1115,6 +1115,23 @@ VPIRValue *vputils::tryToFoldLiveIns(VPSingleDefRecipe &R,
case Instruction::ExtractElement:
assert(!Ops[0]->getType()->isVectorTy() && "Live-ins should be scalar");
return Ops[0];
+ case VPInstruction::ActiveLaneMask: {
+ uint64_t Multiplier = cast<ConstantInt>(Ops[2])->getZExtValue();
+ Type *I1Ty = IntegerType::getInt1Ty(Plan.getContext());
+ if (Plan.hasScalableVF())
+ // We do not produce foldable scalable ALMs at the moment.
+ return nullptr;
+
+ // We do not produce ALMs foldable to false at the moment.
+ unsigned MaxVF = Multiplier * max_element(Plan.vectorFactors(),
+ ElementCount::isKnownLT)
+ ->getFixedValue();
+ if (auto *C = dyn_cast_if_present<Constant>(Folder.FoldIntrinsic(
----------------
artagnon wrote:
The issue is getting access to the context IR function from which to extract the attribute: I guess we could pass OrigLoop into tryToFoldLiveIns, but we're doing it over and over in different functions; I think the best solution would be to record the original IR loop in the Plan, but this would be a design choice, and more long-term. Added TODO for now.
https://github.com/llvm/llvm-project/pull/208852
More information about the llvm-commits
mailing list