[llvm] [VPlan] Fold ALM with const operands (PR #208852)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 15 06:48:42 PDT 2026
================
@@ -1338,6 +1338,26 @@ static VPIRValue *tryToFoldLiveIns(VPSingleDefRecipe &R,
case Instruction::ExtractElement:
assert(!Ops[0]->getType()->isVectorTy() && "Live-ins should be scalar");
return Ops[0];
+ case VPInstruction::ActiveLaneMask: {
+ if (!isa<ConstantInt>(Ops[0]) || !isa<ConstantInt>(Ops[1]) ||
+ Plan.hasScalableVF())
+ return nullptr;
+ uint64_t Base = cast<ConstantInt>(Ops[0])->getZExtValue();
+ uint64_t Limit = cast<ConstantInt>(Ops[1])->getZExtValue();
+ uint64_t Multiplier = cast<ConstantInt>(Ops[2])->getZExtValue();
+ Type *I1Ty = Type::getInt1Ty(Plan.getContext());
+ VPBuilder Builder(&R);
+ unsigned MaxVF =
+ max_element(Plan.vectorFactors(), ElementCount::isKnownLT)
+ ->getFixedValue();
+ unsigned MinVF =
+ min_element(Plan.vectorFactors(), ElementCount::isKnownLT)
+ ->getFixedValue();
+ if (Base + MaxVF * Multiplier < Limit)
+ return ConstantInt::getTrue(I1Ty);
+ if (Base + MinVF * Multiplier > Limit)
+ return ConstantInt::getFalse(I1Ty);
----------------
fhahn wrote:
Do we already have support for folding the intrinsic in `Folder`? If so, could we use that, by providing the maximum element count?
https://github.com/llvm/llvm-project/pull/208852
More information about the llvm-commits
mailing list