@@ -269,9 +269,10 @@ bool Dependence::isScalar(unsigned level) const {
269269// FullDependence methods
270270
271271FullDependence::FullDependence (Instruction *Source, Instruction *Destination,
272+ const SCEVUnionPredicate &Assumes,
272273 bool PossiblyLoopIndependent,
273274 unsigned CommonLevels)
274- : Dependence(Source, Destination), Levels(CommonLevels),
275+ : Dependence(Source, Destination, Assumes ), Levels(CommonLevels),
275276 LoopIndependent(PossiblyLoopIndependent) {
276277 Consistent = true ;
277278 if (CommonLevels)
@@ -711,6 +712,12 @@ void Dependence::dump(raw_ostream &OS) const {
711712 OS << " splitable" ;
712713 }
713714 OS << " !\n " ;
715+
716+ SCEVUnionPredicate Assumptions = getRuntimeAssumptions ();
717+ if (!Assumptions.isAlwaysTrue ()) {
718+ OS << " Runtime Assumptions:\n " ;
719+ Assumptions.print (OS, 2 );
720+ }
714721}
715722
716723// Returns NoAlias/MayAliass/MustAlias for two memory locations based upon their
@@ -3574,7 +3581,7 @@ bool DependenceInfo::invalidate(Function &F, const PreservedAnalyses &PA,
35743581 Inv.invalidate <LoopAnalysis>(F, PA);
35753582}
35763583
3577- SCEVUnionPredicate DependenceInfo::getRuntimeAssumptions () {
3584+ SCEVUnionPredicate DependenceInfo::getRuntimeAssumptions () const {
35783585 return SCEVUnionPredicate (Assumptions, *SE);
35793586}
35803587
@@ -3590,7 +3597,9 @@ SCEVUnionPredicate DependenceInfo::getRuntimeAssumptions() {
35903597// Care is required to keep the routine below, getSplitIteration(),
35913598// up to date with respect to this routine.
35923599std::unique_ptr<Dependence>
3593- DependenceInfo::depends (Instruction *Src, Instruction *Dst) {
3600+ DependenceInfo::depends (Instruction *Src, Instruction *Dst,
3601+ bool UnderRuntimeAssumptions) {
3602+ SmallVector<const SCEVPredicate *, 4 > Assume;
35943603 bool PossiblyLoopIndependent = true ;
35953604 if (Src == Dst)
35963605 PossiblyLoopIndependent = false ;
@@ -3602,7 +3611,8 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst) {
36023611 if (!isLoadOrStore (Src) || !isLoadOrStore (Dst)) {
36033612 // can only analyze simple loads and stores, i.e., no calls, invokes, etc.
36043613 LLVM_DEBUG (dbgs () << " can only handle simple loads and stores\n " );
3605- return std::make_unique<Dependence>(Src, Dst);
3614+ return std::make_unique<Dependence>(Src, Dst,
3615+ SCEVUnionPredicate (Assume, *SE));
36063616 }
36073617
36083618 const MemoryLocation &DstLoc = MemoryLocation::get (Dst);
@@ -3613,7 +3623,8 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst) {
36133623 case AliasResult::PartialAlias:
36143624 // cannot analyse objects if we don't understand their aliasing.
36153625 LLVM_DEBUG (dbgs () << " can't analyze may or partial alias\n " );
3616- return std::make_unique<Dependence>(Src, Dst);
3626+ return std::make_unique<Dependence>(Src, Dst,
3627+ SCEVUnionPredicate (Assume, *SE));
36173628 case AliasResult::NoAlias:
36183629 // If the objects noalias, they are distinct, accesses are independent.
36193630 LLVM_DEBUG (dbgs () << " no alias\n " );
@@ -3626,7 +3637,8 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst) {
36263637 // The dependence test gets confused if the size of the memory accesses
36273638 // differ.
36283639 LLVM_DEBUG (dbgs () << " can't analyze must alias with different sizes\n " );
3629- return std::make_unique<Dependence>(Src, Dst);
3640+ return std::make_unique<Dependence>(Src, Dst,
3641+ SCEVUnionPredicate (Assume, *SE));
36303642 }
36313643
36323644 Value *SrcPtr = getLoadStorePointerOperand (Src);
@@ -3645,7 +3657,8 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst) {
36453657 // We check this upfront so we don't crash in cases where getMinusSCEV()
36463658 // returns a SCEVCouldNotCompute.
36473659 LLVM_DEBUG (dbgs () << " can't analyze SCEV with different pointer base\n " );
3648- return std::make_unique<Dependence>(Src, Dst);
3660+ return std::make_unique<Dependence>(Src, Dst,
3661+ SCEVUnionPredicate (Assume, *SE));
36493662 }
36503663
36513664 uint64_t EltSize = SrcLoc.Size .toRaw ();
@@ -3656,18 +3669,40 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst) {
36563669
36573670 if (Src != Dst) {
36583671 // Check that memory access offsets are multiples of element sizes.
3659- if (!SE->isKnownMultipleOf (SrcEv, EltSize, Assumptions ) ||
3660- !SE->isKnownMultipleOf (DstEv, EltSize, Assumptions )) {
3672+ if (!SE->isKnownMultipleOf (SrcEv, EltSize, Assume ) ||
3673+ !SE->isKnownMultipleOf (DstEv, EltSize, Assume )) {
36613674 LLVM_DEBUG (dbgs () << " can't analyze SCEV with different offsets\n " );
3662- return std::make_unique<Dependence>(Src, Dst);
3675+ return std::make_unique<Dependence>(Src, Dst,
3676+ SCEVUnionPredicate (Assume, *SE));
3677+ }
3678+ }
3679+
3680+ if (!Assume.empty ()) {
3681+ if (!UnderRuntimeAssumptions)
3682+ return std::make_unique<Dependence>(Src, Dst,
3683+ SCEVUnionPredicate (Assume, *SE));
3684+ if (Assumptions.empty ()) {
3685+ Assumptions.append (Assume.begin (), Assume.end ());
3686+ } else {
3687+ // Add non-redundant assumptions.
3688+ unsigned N = Assumptions.size ();
3689+ for (const SCEVPredicate *P : Assume) {
3690+ bool Implied = false ;
3691+ for (unsigned I = 0 ; I != N && !Implied; I++)
3692+ if (Assumptions[I]->implies (P, *SE))
3693+ Implied = true ;
3694+ if (!Implied)
3695+ Assumptions.push_back (P);
3696+ }
36633697 }
36643698 }
36653699
36663700 establishNestingLevels (Src, Dst);
36673701 LLVM_DEBUG (dbgs () << " common nesting levels = " << CommonLevels << " \n " );
36683702 LLVM_DEBUG (dbgs () << " maximum nesting levels = " << MaxLevels << " \n " );
36693703
3670- FullDependence Result (Src, Dst, PossiblyLoopIndependent, CommonLevels);
3704+ FullDependence Result (Src, Dst, SCEVUnionPredicate (Assume, *SE),
3705+ PossiblyLoopIndependent, CommonLevels);
36713706 ++TotalArrayPairs;
36723707
36733708 unsigned Pairs = 1 ;
@@ -4065,7 +4100,7 @@ const SCEV *DependenceInfo::getSplitIteration(const Dependence &Dep,
40654100 // establish loop nesting levels
40664101 establishNestingLevels (Src, Dst);
40674102
4068- FullDependence Result (Src, Dst, false , CommonLevels);
4103+ FullDependence Result (Src, Dst, Dep. Assumptions , false , CommonLevels);
40694104
40704105 unsigned Pairs = 1 ;
40714106 SmallVector<Subscript, 2 > Pair (Pairs);
0 commit comments