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.
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);
}
}
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.