@@ -1168,11 +1168,16 @@ VPlan *VPlan::duplicate() {
11681168 const auto &[NewEntry, __] = cloneFrom (Entry);
11691169
11701170 BasicBlock *ScalarHeaderIRBB = getScalarHeader ()->getIRBasicBlock ();
1171- VPIRBasicBlock *NewScalarHeader = cast<VPIRBasicBlock>(*find_if (
1172- vp_depth_first_shallow (NewEntry), [ScalarHeaderIRBB](VPBlockBase *VPB) {
1173- auto *VPIRBB = dyn_cast<VPIRBasicBlock>(VPB);
1174- return VPIRBB && VPIRBB->getIRBasicBlock () == ScalarHeaderIRBB;
1175- }));
1171+ VPIRBasicBlock *NewScalarHeader = nullptr ;
1172+ if (getScalarHeader ()->getNumPredecessors () == 0 ) {
1173+ NewScalarHeader = createVPIRBasicBlock (ScalarHeaderIRBB);
1174+ } else {
1175+ NewScalarHeader = cast<VPIRBasicBlock>(*find_if (
1176+ vp_depth_first_shallow (NewEntry), [ScalarHeaderIRBB](VPBlockBase *VPB) {
1177+ auto *VPIRBB = dyn_cast<VPIRBasicBlock>(VPB);
1178+ return VPIRBB && VPIRBB->getIRBasicBlock () == ScalarHeaderIRBB;
1179+ }));
1180+ }
11761181 // Create VPlan, clone live-ins and remap operands in the cloned blocks.
11771182 auto *NewPlan = new VPlan (cast<VPBasicBlock>(NewEntry), NewScalarHeader);
11781183 DenseMap<VPValue *, VPValue *> Old2NewVPValues;
@@ -1187,8 +1192,7 @@ VPlan *VPlan::duplicate() {
11871192 NewPlan->BackedgeTakenCount = new VPValue ();
11881193 Old2NewVPValues[BackedgeTakenCount] = NewPlan->BackedgeTakenCount ;
11891194 }
1190- assert (TripCount && " trip count must be set" );
1191- if (TripCount->isLiveIn ())
1195+ if (TripCount && TripCount->isLiveIn ())
11921196 Old2NewVPValues[TripCount] =
11931197 NewPlan->getOrAddLiveIn (TripCount->getLiveInIRValue ());
11941198 // else NewTripCount will be created and inserted into Old2NewVPValues when
@@ -1201,9 +1205,11 @@ VPlan *VPlan::duplicate() {
12011205 NewPlan->UFs = UFs;
12021206 // TODO: Adjust names.
12031207 NewPlan->Name = Name;
1204- assert (Old2NewVPValues.contains (TripCount) &&
1205- " TripCount must have been added to Old2NewVPValues" );
1206- NewPlan->TripCount = Old2NewVPValues[TripCount];
1208+ if (TripCount) {
1209+ assert (Old2NewVPValues.contains (TripCount) &&
1210+ " TripCount must have been added to Old2NewVPValues" );
1211+ NewPlan->TripCount = Old2NewVPValues[TripCount];
1212+ }
12071213
12081214 // Transfer all cloned blocks (the second half of all current blocks) from
12091215 // current to new VPlan.
0 commit comments