[llvm] d72fcee - [VPlan] Add VPValue::isDefinedOutsideVectorRegions helper (NFC).

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 19 05:20:48 PDT 2022


Author: Florian Hahn
Date: 2022-10-19T13:20:30+01:00
New Revision: d72fcee8f47d54a68cab516d7f5a422ba48687f4

URL: https://github.com/llvm/llvm-project/commit/d72fcee8f47d54a68cab516d7f5a422ba48687f4
DIFF: https://github.com/llvm/llvm-project/commit/d72fcee8f47d54a68cab516d7f5a422ba48687f4.diff

LOG: [VPlan] Add VPValue::isDefinedOutsideVectorRegions helper (NFC).

@Ayal suggested a better named helper than using `!getDef()` to check if
a value is invariant across all parts.

The property we are using here is that the VPValue is defined outside
any vector loop region. There's a TODO left to handle recipes defined in
pre-header blocks.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D133666

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
    llvm/lib/Transforms/Vectorize/VPlan.h
    llvm/lib/Transforms/Vectorize/VPlanValue.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index bdeae6fdc33b1..9017481c1905d 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -9659,7 +9659,9 @@ void VPReplicateRecipe::execute(VPTransformState &State) {
     // If the recipe is uniform across all parts (instead of just per VF), only
     // generate a single instance.
     if ((isa<LoadInst>(UI) || isa<StoreInst>(UI)) &&
-        all_of(operands(), [](VPValue *Op) { return !Op->getDef(); })) {
+        all_of(operands(), [](VPValue *Op) {
+          return Op->isDefinedOutsideVectorRegions();
+        })) {
       State.ILV->scalarizeInstruction(UI, this, VPIteration(0, 0), IsPredicated,
                                       State);
       if (user_begin() != user_end()) {

diff  --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 5e7c8c9b969a0..378bc8eb3718f 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -3055,13 +3055,15 @@ VPValue *getOrCreateVPValueForSCEVExpr(VPlan &Plan, const SCEV *Expr,
 
 /// Returns true if \p VPV is uniform after vectorization.
 inline bool isUniformAfterVectorization(VPValue *VPV) {
-  if (auto *Def = VPV->getDef()) {
-    if (auto Rep = dyn_cast<VPReplicateRecipe>(Def))
-      return Rep->isUniform();
-    return false;
-  }
-  // A value without a def is external to vplan and thus uniform.
-  return true;
+  // A value defined outside the vector region must be uniform after
+  // vectorization inside a vector region.
+  if (VPV->isDefinedOutsideVectorRegions())
+    return true;
+  VPDef *Def = VPV->getDef();
+  assert(Def && "Must have definition for value defined inside vector region");
+  if (auto Rep = dyn_cast<VPReplicateRecipe>(Def))
+    return Rep->isUniform();
+  return false;
 }
 } // end namespace vputils
 

diff  --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h
index 3aac5dc70f84e..40c438a42502e 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanValue.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h
@@ -198,6 +198,11 @@ class VPValue {
            "VPValue is not a live-in; it is defined by a VPDef inside a VPlan");
     return getUnderlyingValue();
   }
+
+  /// Returns true if the VPValue is defined outside any vector regions, i.e. it
+  /// is a live-in value.
+  /// TODO: Also handle recipes defined in pre-header blocks.
+  bool isDefinedOutsideVectorRegions() const { return !getDef(); }
 };
 
 typedef DenseMap<Value *, VPValue *> Value2VPValueTy;


        


More information about the llvm-commits mailing list