@@ -222,7 +222,7 @@ VPTransformState::VPTransformState(const TargetTransformInfo *TTI,
222222 Loop *CurrentParentLoop, Type *CanonicalIVTy)
223223 : TTI(TTI), VF(VF), CFG(DT), LI(LI), Builder(Builder), ILV(ILV), Plan(Plan),
224224 CurrentParentLoop(CurrentParentLoop), LVer(nullptr ),
225- TypeAnalysis(CanonicalIVTy), VPDT(*Plan) {}
225+ TypeAnalysis(CanonicalIVTy-> getContext () ), VPDT(*Plan) {}
226226
227227Value *VPTransformState::get (const VPValue *Def, const VPLane &Lane) {
228228 if (Def->isLiveIn ())
@@ -850,7 +850,8 @@ void VPRegionBlock::print(raw_ostream &O, const Twine &Indent,
850850}
851851#endif
852852
853- VPlan::VPlan (Loop *L) {
853+ VPlan::VPlan (Loop *L, Type *InductionTy)
854+ : VectorTripCount(InductionTy), VF(InductionTy), VFxUF(InductionTy) {
854855 setEntry (createVPIRBasicBlock (L->getLoopPreheader ()));
855856 ScalarHeader = createVPIRBasicBlock (L->getHeader ());
856857
@@ -861,7 +862,7 @@ VPlan::VPlan(Loop *L) {
861862}
862863
863864VPlan::~VPlan () {
864- VPValue DummyValue;
865+ VPValue DummyValue ((Type *) nullptr ) ;
865866
866867 for (auto *VPB : CreatedBlocks) {
867868 if (auto *VPBB = dyn_cast<VPBasicBlock>(VPB)) {
@@ -891,10 +892,10 @@ void VPlan::prepareToExecute(Value *TripCountV, Value *VectorTripCountV,
891892 IRBuilder<> Builder (State.CFG .PrevBB ->getTerminator ());
892893 auto *TCMO = Builder.CreateSub (TripCountV, ConstantInt::get (TCTy, 1 ),
893894 " trip.count.minus.1" );
894- BackedgeTakenCount->setUnderlyingValue ( TCMO);
895+ BackedgeTakenCount->replaceAllUsesWith ( getOrAddLiveIn ( TCMO) );
895896 }
896897
897- VectorTripCount.setUnderlyingValue ( VectorTripCountV);
898+ VectorTripCount.replaceAllUsesWith ( getOrAddLiveIn ( VectorTripCountV) );
898899
899900 IRBuilder<> Builder (State.CFG .PrevBB ->getTerminator ());
900901 // FIXME: Model VF * UF computation completely in VPlan.
@@ -903,12 +904,13 @@ void VPlan::prepareToExecute(Value *TripCountV, Value *VectorTripCountV,
903904 unsigned UF = getUF ();
904905 if (VF.getNumUsers ()) {
905906 Value *RuntimeVF = getRuntimeVF (Builder, TCTy, State.VF );
906- VF.setUnderlyingValue ( RuntimeVF);
907- VFxUF.setUnderlyingValue (
907+ VF.replaceAllUsesWith ( getOrAddLiveIn ( RuntimeVF) );
908+ VFxUF.replaceAllUsesWith ( getOrAddLiveIn (
908909 UF > 1 ? Builder.CreateMul (RuntimeVF, ConstantInt::get (TCTy, UF))
909- : RuntimeVF);
910+ : RuntimeVF)) ;
910911 } else {
911- VFxUF.setUnderlyingValue (createStepForVF (Builder, TCTy, State.VF , UF));
912+ VFxUF.replaceAllUsesWith (
913+ getOrAddLiveIn (createStepForVF (Builder, TCTy, State.VF , UF)));
912914 }
913915}
914916
@@ -1175,7 +1177,8 @@ VPlan *VPlan::duplicate() {
11751177 return VPIRBB && VPIRBB->getIRBasicBlock () == ScalarHeaderIRBB;
11761178 }));
11771179 // Create VPlan, clone live-ins and remap operands in the cloned blocks.
1178- auto *NewPlan = new VPlan (cast<VPBasicBlock>(NewEntry), NewScalarHeader);
1180+ auto *NewPlan = new VPlan (cast<VPBasicBlock>(NewEntry), NewScalarHeader,
1181+ getCanonicalIV ()->getScalarType ());
11791182 DenseMap<VPValue *, VPValue *> Old2NewVPValues;
11801183 for (VPValue *OldLiveIn : getLiveIns ()) {
11811184 Old2NewVPValues[OldLiveIn] =
@@ -1185,7 +1188,7 @@ VPlan *VPlan::duplicate() {
11851188 Old2NewVPValues[&VF] = &NewPlan->VF ;
11861189 Old2NewVPValues[&VFxUF] = &NewPlan->VFxUF ;
11871190 if (BackedgeTakenCount) {
1188- NewPlan->BackedgeTakenCount = new VPValue ();
1191+ NewPlan->BackedgeTakenCount = new VPValue ((Type *) nullptr );
11891192 Old2NewVPValues[BackedgeTakenCount] = NewPlan->BackedgeTakenCount ;
11901193 }
11911194 assert (TripCount && " trip count must be set" );
@@ -1371,6 +1374,11 @@ static bool isDefinedInsideLoopRegions(const VPValue *VPV) {
13711374 DefR->getParent ()->getEnclosingLoopRegion ());
13721375}
13731376
1377+ Type *VPValue::getType () const {
1378+ assert (isLiveIn ());
1379+ return SubclassID == VPSymbolicValueSC ? Ty : getUnderlyingValue ()->getType ();
1380+ }
1381+
13741382bool VPValue::isDefinedOutsideLoopRegions () const {
13751383 return !isDefinedInsideLoopRegions (this );
13761384}
0 commit comments