[llvm] [VPlan] Constant-fold ActiveLaneMask intrinsics (PR #208852)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 20 08:53:59 PDT 2026
================
@@ -1120,6 +1120,32 @@ VPIRValue *vputils::tryToFoldLiveIns(VPSingleDefRecipe &R,
case Instruction::ExtractElement:
assert(!Ops[0]->getType()->isVectorTy() && "Live-ins should be scalar");
return Ops[0];
+ case VPInstruction::ActiveLaneMask:
+ case VPInstruction::WideActiveLaneMask: {
+ uint64_t Multiplier = 1;
+ if (Opcode == VPInstruction::WideActiveLaneMask) {
+ Multiplier = cast<ConstantInt>(Ops[2])->getZExtValue();
+ Ops.pop_back();
+ }
+ Type *I1Ty = IntegerType::getInt1Ty(Plan.getContext());
+ ElementCount MaxVF =
+ max_element(Plan.vectorFactors(), ElementCount::isKnownLT)
+ ->multiplyCoefficientBy(Multiplier);
+
+ // We rely on the fact that there is one VPlan for fixed-vectors and
+ // another for scalable-vectors: we can only proceed with the scalable
+ // VPlan if a vscale_range function attribute was found.
+ if (MaxVF.isScalable() && !Plan.getMaxVScale())
+ return nullptr;
+ uint64_t MaxVFScaled = MaxVF.getKnownMinValue() *
+ (MaxVF.isScalable() ? *Plan.getMaxVScale() : 1);
+ if (auto *C = dyn_cast_if_present<Constant>(
+ Folder.FoldIntrinsic(Intrinsic::get_active_lane_mask, Ops,
+ FixedVectorType::get(I1Ty, MaxVFScaled))))
----------------
fhahn wrote:
Thanks! Do we need a similar guard in `ConstantFoldFixedVectorCall` for a test case which already has the problematic `@llvm.get.active.lane.mask` form in the IR?
https://github.com/llvm/llvm-project/pull/208852
More information about the llvm-commits
mailing list