[llvm] 165e36b - [VPlan] Assert can IV is only used by increments during epilogue vec.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 19 02:10:26 PST 2022


Author: Florian Hahn
Date: 2022-01-19T10:10:05Z
New Revision: 165e36bf180eecb32fa5442fd5c4d43388a136fb

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

LOG: [VPlan] Assert can IV is only used by increments during epilogue vec.

After resetting the start value of the canonical IV, it might not be
canonical any more. Add an assertion to make sure it is only used by its
increment, to avoid potential mis-use. Suggested in D117140.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index 2598b5bd24be9..04c8e399c5438 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -871,6 +871,16 @@ void VPlan::prepareToExecute(Value *TripCountV, Value *VectorTripCountV,
     VPValue *VPV = new VPValue(CanonicalIVStartValue);
     addExternalDef(VPV);
     auto *IV = getCanonicalIV();
+    assert(all_of(IV->users(),
+                  [](const VPUser *U) {
+                    auto *VPI = cast<VPInstruction>(U);
+                    return VPI->getOpcode() ==
+                               VPInstruction::CanonicalIVIncrement ||
+                           VPI->getOpcode() ==
+                               VPInstruction::CanonicalIVIncrementNUW;
+                  }) &&
+           "the canonical IV should only be used by its increments when "
+           "resetting the start value");
     IV->setOperand(0, VPV);
   }
 }

diff  --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 585fe759994c1..c7946b6d2adef 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -836,6 +836,16 @@ class VPInstruction : public VPRecipeBase, public VPValue {
     return R->getVPDefID() == VPRecipeBase::VPInstructionSC;
   }
 
+  /// Extra classof implementations to allow directly casting from VPUser ->
+  /// VPInstruction.
+  static inline bool classof(const VPUser *U) {
+    auto *R = dyn_cast<VPRecipeBase>(U);
+    return R && R->getVPDefID() == VPRecipeBase::VPInstructionSC;
+  }
+  static inline bool classof(const VPRecipeBase *R) {
+    return R->getVPDefID() == VPRecipeBase::VPInstructionSC;
+  }
+
   unsigned getOpcode() const { return Opcode; }
 
   /// Generate the instruction.


        


More information about the llvm-commits mailing list