[llvm] [VPlan] Fold ALM with const operands (PR #208852)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 16 07:21:25 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);
----------------
artagnon wrote:
Yes we do, but I'm currently working on multiple patches to enable const-folding in InstSimplifyFolder: we either review and merge this now, simplifying later, or wait for those to land?
https://github.com/llvm/llvm-project/pull/208852
More information about the llvm-commits
mailing list