From: Florian Hahn Date: Wed, 19 Jan 2022 10:09:46 +0000 (+0000) Subject: [VPlan] Assert can IV is only used by increments during epilogue vec. X-Git-Tag: upstream/15.0.7~19975 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=165e36bf180eecb32fa5442fd5c4d43388a136fb;p=platform%2Fupstream%2Fllvm.git [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. --- diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp index 2598b5b..04c8e39 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(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 585fe75..c7946b6 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -836,6 +836,16 @@ public: 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(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.