@@ -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,
@@ -3953,8 +3944,6 @@ SCEVUnionPredicate DependenceInfo::getRuntimeAssumptions() const {
39533944// Goff, Kennedy, Tseng
39543945// PLDI 1991
39553946//
3956- // Care is required to keep the routine below, getSplitIteration(),
3957- // up to date with respect to this routine.
39583947std::unique_ptr<Dependence>
39593948DependenceInfo::depends (Instruction *Src, Instruction *Dst,
39603949 bool UnderRuntimeAssumptions) {
@@ -4160,11 +4149,9 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
41604149 case Subscript::SIV: {
41614150 LLVM_DEBUG (dbgs () << " , SIV\n " );
41624151 unsigned Level;
4163- const SCEV *SplitIter = nullptr ;
41644152 Constraint NewConstraint;
41654153 NewConstraint.setAny (SE);
4166- if (testSIV (Pair[SI].Src , Pair[SI].Dst , Level, Result, NewConstraint,
4167- SplitIter))
4154+ if (testSIV (Pair[SI].Src , Pair[SI].Dst , Level, Result, NewConstraint))
41684155 return nullptr ;
41694156 break ;
41704157 }
@@ -4258,133 +4245,3 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
42584245
42594246 return std::make_unique<FullDependence>(std::move (Result));
42604247}
4261-
4262- // ===----------------------------------------------------------------------===//
4263- // getSplitIteration -
4264- // Rather than spend rarely-used space recording the splitting iteration
4265- // during the Weak-Crossing SIV test, we re-compute it on demand.
4266- // The re-computation is basically a repeat of the entire dependence test,
4267- // though simplified since we know that the dependence exists.
4268- // It's tedious, since we must go through all propagations, etc.
4269- //
4270- // Care is required to keep this code up to date with respect to the routine
4271- // above, depends().
4272- //
4273- // Generally, the dependence analyzer will be used to build
4274- // a dependence graph for a function (basically a map from instructions
4275- // to dependences). Looking for cycles in the graph shows us loops
4276- // that cannot be trivially vectorized/parallelized.
4277- //
4278- // We can try to improve the situation by examining all the dependences
4279- // that make up the cycle, looking for ones we can break.
4280- // Sometimes, peeling the first or last iteration of a loop will break
4281- // dependences, and we've got flags for those possibilities.
4282- // Sometimes, splitting a loop at some other iteration will do the trick,
4283- // and we've got a flag for that case. Rather than waste the space to
4284- // record the exact iteration (since we rarely know), we provide
4285- // a method that calculates the iteration. It's a drag that it must work
4286- // from scratch, but wonderful in that it's possible.
4287- //
4288- // Here's an example:
4289- //
4290- // for (i = 0; i < 10; i++)
4291- // A[i] = ...
4292- // ... = A[11 - i]
4293- //
4294- // There's a loop-carried flow dependence from the store to the load,
4295- // found by the weak-crossing SIV test. The dependence will have a flag,
4296- // indicating that the dependence can be broken by splitting the loop.
4297- // Calling getSplitIteration will return 5.
4298- // Splitting the loop breaks the dependence, like so:
4299- //
4300- // for (i = 0; i <= 5; i++)
4301- // A[i] = ...
4302- // ... = A[11 - i]
4303- // for (i = 6; i < 10; i++)
4304- // A[i] = ...
4305- // ... = A[11 - i]
4306- //
4307- // breaks the dependence and allows us to vectorize/parallelize
4308- // both loops.
4309- const SCEV *DependenceInfo::getSplitIteration (const Dependence &Dep,
4310- unsigned SplitLevel) {
4311- assert (Dep.isSplitable (SplitLevel) &&
4312- " Dep should be splitable at SplitLevel" );
4313- Instruction *Src = Dep.getSrc ();
4314- Instruction *Dst = Dep.getDst ();
4315- assert (Src->mayReadFromMemory () || Src->mayWriteToMemory ());
4316- assert (Dst->mayReadFromMemory () || Dst->mayWriteToMemory ());
4317- assert (isLoadOrStore (Src));
4318- assert (isLoadOrStore (Dst));
4319- Value *SrcPtr = getLoadStorePointerOperand (Src);
4320- Value *DstPtr = getLoadStorePointerOperand (Dst);
4321- assert (underlyingObjectsAlias (
4322- AA, F->getDataLayout (), MemoryLocation::get (Dst),
4323- MemoryLocation::get (Src)) == AliasResult::MustAlias);
4324-
4325- // establish loop nesting levels
4326- establishNestingLevels (Src, Dst);
4327-
4328- FullDependence Result (Src, Dst, Dep.Assumptions , false , CommonLevels);
4329-
4330- unsigned Pairs = 1 ;
4331- SmallVector<Subscript, 2 > Pair (Pairs);
4332- const SCEV *SrcSCEV = SE->getSCEV (SrcPtr);
4333- const SCEV *DstSCEV = SE->getSCEV (DstPtr);
4334- Pair[0 ].Src = SE->removePointerBase (SrcSCEV);
4335- Pair[0 ].Dst = SE->removePointerBase (DstSCEV);
4336-
4337- if (Delinearize) {
4338- if (tryDelinearize (Src, Dst, Pair)) {
4339- LLVM_DEBUG (dbgs () << " delinearized\n " );
4340- Pairs = Pair.size ();
4341- }
4342- }
4343-
4344- for (unsigned P = 0 ; P < Pairs; ++P) {
4345- assert (Pair[P].Src ->getType ()->isIntegerTy () && " Src must be an integer" );
4346- assert (Pair[P].Dst ->getType ()->isIntegerTy () && " Dst must be an integer" );
4347- Pair[P].Loops .resize (MaxLevels + 1 );
4348- Pair[P].GroupLoops .resize (MaxLevels + 1 );
4349- Pair[P].Group .resize (Pairs);
4350- removeMatchingExtensions (&Pair[P]);
4351- Pair[P].Classification =
4352- classifyPair (Pair[P].Src , LI->getLoopFor (Src->getParent ()), Pair[P].Dst ,
4353- LI->getLoopFor (Dst->getParent ()), Pair[P].Loops );
4354- Pair[P].GroupLoops = Pair[P].Loops ;
4355- Pair[P].Group .set (P);
4356- }
4357-
4358- Constraint NewConstraint;
4359- NewConstraint.setAny (SE);
4360-
4361- // Test each subscript individually for split iteration
4362- for (unsigned SI = 0 ; SI < Pairs; ++SI) {
4363- switch (Pair[SI].Classification ) {
4364- case Subscript::NonLinear:
4365- // ignore these, but collect loops for later
4366- collectCommonLoops (Pair[SI].Src , LI->getLoopFor (Src->getParent ()),
4367- Pair[SI].Loops );
4368- collectCommonLoops (Pair[SI].Dst , LI->getLoopFor (Dst->getParent ()),
4369- Pair[SI].Loops );
4370- Result.Consistent = false ;
4371- break ;
4372- case Subscript::SIV: {
4373- unsigned Level;
4374- const SCEV *SplitIter = nullptr ;
4375- (void )testSIV (Pair[SI].Src , Pair[SI].Dst , Level, Result, NewConstraint,
4376- SplitIter);
4377- if (Level == SplitLevel && SplitIter != nullptr ) {
4378- return SplitIter;
4379- }
4380- break ;
4381- }
4382- case Subscript::ZIV:
4383- case Subscript::RDIV:
4384- case Subscript::MIV:
4385- break ;
4386- }
4387- }
4388- // No split iteration found
4389- return nullptr ;
4390- }
0 commit comments