[llvm] [VPlan] Constant-fold ActiveLaneMask intrinsics (PR #208852)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 2 05:09:48 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:
Patch re-done, although it's more of a hobby task now than anything: the real optimization benefit is negligible :)
https://github.com/llvm/llvm-project/pull/208852
More information about the llvm-commits
mailing list