[llvm] [VPlan] Implement interleaving as VPlan-to-VPlan transform. (PR #95842)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 3 15:24:32 PDT 2024
================
@@ -3825,6 +3862,41 @@ inline bool isUniformAfterVectorization(const VPValue *VPV) {
/// Return true if \p V is a header mask in \p Plan.
bool isHeaderMask(const VPValue *V, VPlan &Plan);
+
+/// Checks if \p C is uniform across all VF lanes and UF parts. It is considered
+/// as such if it is either loop invariant (defined outside the vector region)
+/// or its operand is known to be uniform across all VFs and UFs (e.g.
+/// VPDerivedIV or VPCanonicalIVPHI).
+inline bool isUniformAcrossVFsAndUFs(VPValue *V) {
+ // Loop invariants are uniform:
+ if (V->isDefinedOutsideVectorRegions())
+ return true;
+
+ auto *R = V->getDefiningRecipe();
+ // Canonical IV chain is uniform:
+ auto *CanonicalIV = R->getParent()->getPlan()->getCanonicalIV();
+ if (R == CanonicalIV || V == CanonicalIV->getBackedgeValue())
+ return true;
+
+ // DerivedIV is uniform:
+ if (isa<VPDerivedIVRecipe>(R))
+ return true;
+
+ // Loads and stores that are uniform across VF lanes are handled by
+ // VPReplicateRecipe.IsUniform. They are also uniform across UF parts if all
+ // their operands are invariant:
+ if (isa<VPReplicateRecipe>(V) && cast<VPReplicateRecipe>(V)->isUniform() &&
+ (isa<LoadInst, StoreInst>(V->getUnderlyingValue())) &&
+ all_of(R->operands(),
+ [](VPValue *Op) { return Op->isDefinedOutsideVectorRegions(); }))
+ return true;
+
+ return isa<VPScalarCastRecipe, VPWidenCastRecipe>(R) &&
+ (R->getOperand(0)->isLiveIn() ||
+ isa<VPDerivedIVRecipe>(R->getOperand(0)) ||
+ isa<VPCanonicalIVPHIRecipe>(R->getOperand(0)));
----------------
ayalz wrote:
```suggestion
if (isa<VPScalarCastRecipe, VPWidenCastRecipe>(R))
return isUniformAcrossVFsAndUFs(R->getOperand(0));
// A values is considered non-uniform unless proven otherwise.
return false;
```
https://github.com/llvm/llvm-project/pull/95842
More information about the llvm-commits
mailing list