@@ -1168,11 +1168,16 @@ VPlan *VPlan::duplicate() {
1168
1168
const auto &[NewEntry, __] = cloneFrom (Entry);
1169
1169
1170
1170
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
+ }
1176
1181
// Create VPlan, clone live-ins and remap operands in the cloned blocks.
1177
1182
auto *NewPlan = new VPlan (cast<VPBasicBlock>(NewEntry), NewScalarHeader);
1178
1183
DenseMap<VPValue *, VPValue *> Old2NewVPValues;
@@ -1187,8 +1192,7 @@ VPlan *VPlan::duplicate() {
1187
1192
NewPlan->BackedgeTakenCount = new VPValue ();
1188
1193
Old2NewVPValues[BackedgeTakenCount] = NewPlan->BackedgeTakenCount ;
1189
1194
}
1190
- assert (TripCount && " trip count must be set" );
1191
- if (TripCount->isLiveIn ())
1195
+ if (TripCount && TripCount->isLiveIn ())
1192
1196
Old2NewVPValues[TripCount] =
1193
1197
NewPlan->getOrAddLiveIn (TripCount->getLiveInIRValue ());
1194
1198
// else NewTripCount will be created and inserted into Old2NewVPValues when
@@ -1201,9 +1205,11 @@ VPlan *VPlan::duplicate() {
1201
1205
NewPlan->UFs = UFs;
1202
1206
// TODO: Adjust names.
1203
1207
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
+ }
1207
1213
1208
1214
// Transfer all cloned blocks (the second half of all current blocks) from
1209
1215
// current to new VPlan.
0 commit comments