@@ -445,7 +445,6 @@ static void dumpExampleDependence(raw_ostream &OS, DependenceInfo *DA,
445445 for (unsigned Level = 1 ; Level <= D->getLevels (); Level++) {
446446 if (D->isSplitable (Level)) {
447447 OS << " da analyze - split level = " << Level;
448- OS << " , iteration = " << *DA->getSplitIteration (*D, Level);
449448 OS << " !\n " ;
450449 }
451450 }
@@ -1825,8 +1824,7 @@ bool DependenceInfo::strongSIVtest(const SCEV *Coeff, const SCEV *SrcConst,
18251824bool DependenceInfo::weakCrossingSIVtest (
18261825 const SCEV *Coeff, const SCEV *SrcConst, const SCEV *DstConst,
18271826 const Loop *CurSrcLoop, const Loop *CurDstLoop, unsigned Level,
1828- FullDependence &Result, Constraint &NewConstraint,
1829- const SCEV *&SplitIter) const {
1827+ FullDependence &Result, Constraint &NewConstraint) const {
18301828 if (!isDependenceTestEnabled (DependenceTestType::WeakCrossingSIV))
18311829 return false ;
18321830
@@ -1865,12 +1863,6 @@ bool DependenceInfo::weakCrossingSIVtest(
18651863 }
18661864 assert (SE->isKnownPositive (ConstCoeff) && " ConstCoeff should be positive" );
18671865
1868- // compute SplitIter for use by DependenceInfo::getSplitIteration()
1869- SplitIter = SE->getUDivExpr (
1870- SE->getSMaxExpr (SE->getZero (Delta->getType ()), Delta),
1871- SE->getMulExpr (SE->getConstant (Delta->getType (), 2 ), ConstCoeff));
1872- LLVM_DEBUG (dbgs () << " \t Split iter = " << *SplitIter << " \n " );
1873-
18741866 const SCEVConstant *ConstDelta = dyn_cast<SCEVConstant>(Delta);
18751867 if (!ConstDelta)
18761868 return false ;
@@ -2731,8 +2723,8 @@ bool DependenceInfo::symbolicRDIVtest(const SCEV *A1, const SCEV *A2,
27312723//
27322724// Return true if dependence disproved.
27332725bool DependenceInfo::testSIV (const SCEV *Src, const SCEV *Dst, unsigned &Level,
2734- FullDependence &Result, Constraint &NewConstraint,
2735- const SCEV *&SplitIter ) const {
2726+ FullDependence &Result,
2727+ Constraint &NewConstraint ) const {
27362728 LLVM_DEBUG (dbgs () << " src = " << *Src << " \n " );
27372729 LLVM_DEBUG (dbgs () << " dst = " << *Dst << " \n " );
27382730 const SCEVAddRecExpr *SrcAddRec = dyn_cast<SCEVAddRecExpr>(Src);
@@ -2754,8 +2746,7 @@ bool DependenceInfo::testSIV(const SCEV *Src, const SCEV *Dst, unsigned &Level,
27542746 CurDstLoop, Level, Result, NewConstraint);
27552747 else if (SrcCoeff == SE->getNegativeSCEV (DstCoeff))
27562748 disproven = weakCrossingSIVtest (SrcCoeff, SrcConst, DstConst, CurSrcLoop,
2757- CurDstLoop, Level, Result, NewConstraint,
2758- SplitIter);
2749+ CurDstLoop, Level, Result, NewConstraint);
27592750 else
27602751 disproven =
27612752 exactSIVtest (SrcCoeff, DstCoeff, SrcConst, DstConst, CurSrcLoop,
@@ -3951,8 +3942,6 @@ SCEVUnionPredicate DependenceInfo::getRuntimeAssumptions() const {
39513942// Goff, Kennedy, Tseng
39523943// PLDI 1991
39533944//
3954- // Care is required to keep the routine below, getSplitIteration(),
3955- // up to date with respect to this routine.
39563945std::unique_ptr<Dependence>
39573946DependenceInfo::depends (Instruction *Src, Instruction *Dst,
39583947 bool UnderRuntimeAssumptions) {
@@ -4158,11 +4147,9 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
41584147 case Subscript::SIV: {
41594148 LLVM_DEBUG (dbgs () << " , SIV\n " );
41604149 unsigned Level;
4161- const SCEV *SplitIter = nullptr ;
41624150 Constraint NewConstraint;
41634151 NewConstraint.setAny (SE);
4164- if (testSIV (Pair[SI].Src , Pair[SI].Dst , Level, Result, NewConstraint,
4165- SplitIter))
4152+ if (testSIV (Pair[SI].Src , Pair[SI].Dst , Level, Result, NewConstraint))
41664153 return nullptr ;
41674154 break ;
41684155 }
@@ -4256,133 +4243,3 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
42564243
42574244 return std::make_unique<FullDependence>(std::move (Result));
42584245}
4259-
4260- // ===----------------------------------------------------------------------===//
4261- // getSplitIteration -
4262- // Rather than spend rarely-used space recording the splitting iteration
4263- // during the Weak-Crossing SIV test, we re-compute it on demand.
4264- // The re-computation is basically a repeat of the entire dependence test,
4265- // though simplified since we know that the dependence exists.
4266- // It's tedious, since we must go through all propagations, etc.
4267- //
4268- // Care is required to keep this code up to date with respect to the routine
4269- // above, depends().
4270- //
4271- // Generally, the dependence analyzer will be used to build
4272- // a dependence graph for a function (basically a map from instructions
4273- // to dependences). Looking for cycles in the graph shows us loops
4274- // that cannot be trivially vectorized/parallelized.
4275- //
4276- // We can try to improve the situation by examining all the dependences
4277- // that make up the cycle, looking for ones we can break.
4278- // Sometimes, peeling the first or last iteration of a loop will break
4279- // dependences, and we've got flags for those possibilities.
4280- // Sometimes, splitting a loop at some other iteration will do the trick,
4281- // and we've got a flag for that case. Rather than waste the space to
4282- // record the exact iteration (since we rarely know), we provide
4283- // a method that calculates the iteration. It's a drag that it must work
4284- // from scratch, but wonderful in that it's possible.
4285- //
4286- // Here's an example:
4287- //
4288- // for (i = 0; i < 10; i++)
4289- // A[i] = ...
4290- // ... = A[11 - i]
4291- //
4292- // There's a loop-carried flow dependence from the store to the load,
4293- // found by the weak-crossing SIV test. The dependence will have a flag,
4294- // indicating that the dependence can be broken by splitting the loop.
4295- // Calling getSplitIteration will return 5.
4296- // Splitting the loop breaks the dependence, like so:
4297- //
4298- // for (i = 0; i <= 5; i++)
4299- // A[i] = ...
4300- // ... = A[11 - i]
4301- // for (i = 6; i < 10; i++)
4302- // A[i] = ...
4303- // ... = A[11 - i]
4304- //
4305- // breaks the dependence and allows us to vectorize/parallelize
4306- // both loops.
4307- const SCEV *DependenceInfo::getSplitIteration (const Dependence &Dep,
4308- unsigned SplitLevel) {
4309- assert (Dep.isSplitable (SplitLevel) &&
4310- " Dep should be splitable at SplitLevel" );
4311- Instruction *Src = Dep.getSrc ();
4312- Instruction *Dst = Dep.getDst ();
4313- assert (Src->mayReadFromMemory () || Src->mayWriteToMemory ());
4314- assert (Dst->mayReadFromMemory () || Dst->mayWriteToMemory ());
4315- assert (isLoadOrStore (Src));
4316- assert (isLoadOrStore (Dst));
4317- Value *SrcPtr = getLoadStorePointerOperand (Src);
4318- Value *DstPtr = getLoadStorePointerOperand (Dst);
4319- assert (underlyingObjectsAlias (
4320- AA, F->getDataLayout (), MemoryLocation::get (Dst),
4321- MemoryLocation::get (Src)) == AliasResult::MustAlias);
4322-
4323- // establish loop nesting levels
4324- establishNestingLevels (Src, Dst);
4325-
4326- FullDependence Result (Src, Dst, Dep.Assumptions , false , CommonLevels);
4327-
4328- unsigned Pairs = 1 ;
4329- SmallVector<Subscript, 2 > Pair (Pairs);
4330- const SCEV *SrcSCEV = SE->getSCEV (SrcPtr);
4331- const SCEV *DstSCEV = SE->getSCEV (DstPtr);
4332- Pair[0 ].Src = SE->removePointerBase (SrcSCEV);
4333- Pair[0 ].Dst = SE->removePointerBase (DstSCEV);
4334-
4335- if (Delinearize) {
4336- if (tryDelinearize (Src, Dst, Pair)) {
4337- LLVM_DEBUG (dbgs () << " delinearized\n " );
4338- Pairs = Pair.size ();
4339- }
4340- }
4341-
4342- for (unsigned P = 0 ; P < Pairs; ++P) {
4343- assert (Pair[P].Src ->getType ()->isIntegerTy () && " Src must be an integer" );
4344- assert (Pair[P].Dst ->getType ()->isIntegerTy () && " Dst must be an integer" );
4345- Pair[P].Loops .resize (MaxLevels + 1 );
4346- Pair[P].GroupLoops .resize (MaxLevels + 1 );
4347- Pair[P].Group .resize (Pairs);
4348- removeMatchingExtensions (&Pair[P]);
4349- Pair[P].Classification =
4350- classifyPair (Pair[P].Src , LI->getLoopFor (Src->getParent ()), Pair[P].Dst ,
4351- LI->getLoopFor (Dst->getParent ()), Pair[P].Loops );
4352- Pair[P].GroupLoops = Pair[P].Loops ;
4353- Pair[P].Group .set (P);
4354- }
4355-
4356- Constraint NewConstraint;
4357- NewConstraint.setAny (SE);
4358-
4359- // Test each subscript individually for split iteration
4360- for (unsigned SI = 0 ; SI < Pairs; ++SI) {
4361- switch (Pair[SI].Classification ) {
4362- case Subscript::NonLinear:
4363- // ignore these, but collect loops for later
4364- collectCommonLoops (Pair[SI].Src , LI->getLoopFor (Src->getParent ()),
4365- Pair[SI].Loops );
4366- collectCommonLoops (Pair[SI].Dst , LI->getLoopFor (Dst->getParent ()),
4367- Pair[SI].Loops );
4368- Result.Consistent = false ;
4369- break ;
4370- case Subscript::SIV: {
4371- unsigned Level;
4372- const SCEV *SplitIter = nullptr ;
4373- (void )testSIV (Pair[SI].Src , Pair[SI].Dst , Level, Result, NewConstraint,
4374- SplitIter);
4375- if (Level == SplitLevel && SplitIter != nullptr ) {
4376- return SplitIter;
4377- }
4378- break ;
4379- }
4380- case Subscript::ZIV:
4381- case Subscript::RDIV:
4382- case Subscript::MIV:
4383- break ;
4384- }
4385- }
4386- // No split iteration found
4387- return nullptr ;
4388- }
0 commit comments