[llvm] [VPlan] Constant-fold ActiveLaneMask intrinsics (PR #208852)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 22 02:17:18 PDT 2026
================
@@ -1179,6 +1179,43 @@ 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) {
+ // Optimizing WideALM can only happen after the Plan is unrolled.
+ if (!Plan.isUnrolled())
+ return nullptr;
+ 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.
+ std::optional<unsigned> MaxVScale = getMaxVScale(Plan.getIRFunction());
+ if (MaxVF.isScalable() && !MaxVScale)
+ return nullptr;
+ bool Overflow;
+ unsigned MaxVFScaled =
+ SaturatingMultiply(MaxVF.getKnownMinValue(),
+ (MaxVF.isScalable() ? *MaxVScale : 1), &Overflow);
+ if (Overflow)
+ return nullptr;
+ if (auto *C = dyn_cast_if_present<Constant>(
+ Folder.FoldIntrinsic(Intrinsic::get_active_lane_mask, Ops,
+ FixedVectorType::get(I1Ty, MaxVFScaled))))
----------------
artagnon wrote:
Perhaps my misunderstanding of the red +0.05%, but sure, I can put the CxtF in the SQ, thanks for checking!
https://github.com/llvm/llvm-project/pull/208852
More information about the llvm-commits
mailing list