@@ -3567,7 +3567,7 @@ bool DependenceInfo::invalidate(Function &F, const PreservedAnalyses &PA,
35673567}
35683568
35693569SCEVUnionPredicate DependenceInfo::getRuntimeAssumptions () const {
3570- return SCEVUnionPredicate ( Assumptions, *SE) ;
3570+ return Assumptions;
35713571}
35723572
35733573// depends -
@@ -3584,7 +3584,12 @@ SCEVUnionPredicate DependenceInfo::getRuntimeAssumptions() const {
35843584std::unique_ptr<Dependence>
35853585DependenceInfo::depends (Instruction *Src, Instruction *Dst,
35863586 bool UnderRuntimeAssumptions) {
3587- SmallVector<const SCEVPredicate *, 4 > Assume;
3587+ // Set the flag for whether we're allowed to add runtime assumptions.
3588+ this ->UnderRuntimeAssumptions = UnderRuntimeAssumptions;
3589+
3590+ // Clear any previous assumptions
3591+ Assumptions = SCEVUnionPredicate ({}, *SE);
3592+
35883593 bool PossiblyLoopIndependent = true ;
35893594 if (Src == Dst)
35903595 PossiblyLoopIndependent = false ;
@@ -3596,8 +3601,7 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
35963601 if (!isLoadOrStore (Src) || !isLoadOrStore (Dst)) {
35973602 // can only analyze simple loads and stores, i.e., no calls, invokes, etc.
35983603 LLVM_DEBUG (dbgs () << " can only handle simple loads and stores\n " );
3599- return std::make_unique<Dependence>(Src, Dst,
3600- SCEVUnionPredicate (Assume, *SE));
3604+ return std::make_unique<Dependence>(Src, Dst, getRuntimeAssumptions ());
36013605 }
36023606
36033607 const MemoryLocation &DstLoc = MemoryLocation::get (Dst);
@@ -3608,8 +3612,7 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
36083612 case AliasResult::PartialAlias:
36093613 // cannot analyse objects if we don't understand their aliasing.
36103614 LLVM_DEBUG (dbgs () << " can't analyze may or partial alias\n " );
3611- return std::make_unique<Dependence>(Src, Dst,
3612- SCEVUnionPredicate (Assume, *SE));
3615+ return std::make_unique<Dependence>(Src, Dst, getRuntimeAssumptions ());
36133616 case AliasResult::NoAlias:
36143617 // If the objects noalias, they are distinct, accesses are independent.
36153618 LLVM_DEBUG (dbgs () << " no alias\n " );
@@ -3623,8 +3626,7 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
36233626 // The dependence test gets confused if the size of the memory accesses
36243627 // differ.
36253628 LLVM_DEBUG (dbgs () << " can't analyze must alias with different sizes\n " );
3626- return std::make_unique<Dependence>(Src, Dst,
3627- SCEVUnionPredicate (Assume, *SE));
3629+ return std::make_unique<Dependence>(Src, Dst, getRuntimeAssumptions ());
36283630 }
36293631
36303632 Value *SrcPtr = getLoadStorePointerOperand (Src);
@@ -3643,8 +3645,7 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
36433645 // We check this upfront so we don't crash in cases where getMinusSCEV()
36443646 // returns a SCEVCouldNotCompute.
36453647 LLVM_DEBUG (dbgs () << " can't analyze SCEV with different pointer base\n " );
3646- return std::make_unique<Dependence>(Src, Dst,
3647- SCEVUnionPredicate (Assume, *SE));
3648+ return std::make_unique<Dependence>(Src, Dst, getRuntimeAssumptions ());
36483649 }
36493650
36503651 // Even if the base pointers are the same, they may not be loop-invariant. It
@@ -3656,44 +3657,48 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
36563657 if (!isLoopInvariant (SrcBase, SrcLoop) ||
36573658 !isLoopInvariant (DstBase, DstLoop)) {
36583659 LLVM_DEBUG (dbgs () << " The base pointer is not loop invariant.\n " );
3659- return std::make_unique<Dependence>(Src, Dst,
3660- SCEVUnionPredicate (Assume, *SE));
3660+ return std::make_unique<Dependence>(Src, Dst, getRuntimeAssumptions ());
36613661 }
36623662
36633663 uint64_t EltSize = SrcLoc.Size .toRaw ();
36643664 const SCEV *SrcEv = SE->getMinusSCEV (SrcSCEV, SrcBase);
36653665 const SCEV *DstEv = SE->getMinusSCEV (DstSCEV, DstBase);
36663666
36673667 // Check that memory access offsets are multiples of element sizes.
3668- if (!SE->isKnownMultipleOf (SrcEv, EltSize, Assume) ||
3669- !SE->isKnownMultipleOf (DstEv, EltSize, Assume)) {
3668+ SmallVector<const SCEVPredicate *, 4 > TempAssumptions;
3669+ if (!SE->isKnownMultipleOf (SrcEv, EltSize, TempAssumptions) ||
3670+ !SE->isKnownMultipleOf (DstEv, EltSize, TempAssumptions)) {
36703671 LLVM_DEBUG (dbgs () << " can't analyze SCEV with different offsets\n " );
3671- return std::make_unique<Dependence>(Src, Dst,
3672- SCEVUnionPredicate (Assume, *SE));
3672+ return std::make_unique<Dependence>(Src, Dst, getRuntimeAssumptions ());
36733673 }
36743674
3675- if (!Assume.empty ()) {
3676- if (!UnderRuntimeAssumptions)
3677- return std::make_unique<Dependence>(Src, Dst,
3678- SCEVUnionPredicate (Assume, *SE));
3679- // Add non-redundant assumptions.
3680- unsigned N = Assumptions.size ();
3681- for (const SCEVPredicate *P : Assume) {
3682- bool Implied = false ;
3683- for (unsigned I = 0 ; I != N && !Implied; I++)
3684- if (Assumptions[I]->implies (P, *SE))
3685- Implied = true ;
3686- if (!Implied)
3687- Assumptions.push_back (P);
3675+ // Add any new assumptions from the isKnownMultipleOf calls
3676+ if (!TempAssumptions.empty ()) {
3677+ if (UnderRuntimeAssumptions) {
3678+ SmallVector<const SCEVPredicate *, 4 > NewPreds (
3679+ Assumptions.getPredicates ());
3680+ NewPreds.append (TempAssumptions.begin (), TempAssumptions.end ());
3681+ const_cast <DependenceInfo *>(this )->Assumptions =
3682+ SCEVUnionPredicate (NewPreds, *SE);
3683+ } else {
3684+ // Runtime assumptions needed but not allowed.
3685+ // Return confused dependence since we cannot proceed with precise
3686+ // analysis.
3687+ LLVM_DEBUG (dbgs () << " Runtime assumptions needed for offset analysis but "
3688+ " not allowed\n " );
3689+ return std::make_unique<Dependence>(Src, Dst, getRuntimeAssumptions ());
36883690 }
36893691 }
36903692
3693+ // Assert that we haven't added runtime assumptions when not allowed
3694+ assert (UnderRuntimeAssumptions || Assumptions.isAlwaysTrue ());
3695+
36913696 establishNestingLevels (Src, Dst);
36923697 LLVM_DEBUG (dbgs () << " common nesting levels = " << CommonLevels << " \n " );
36933698 LLVM_DEBUG (dbgs () << " maximum nesting levels = " << MaxLevels << " \n " );
36943699
3695- FullDependence Result (Src, Dst, SCEVUnionPredicate (Assume, *SE) ,
3696- PossiblyLoopIndependent, CommonLevels);
3700+ FullDependence Result (Src, Dst, Assumptions, PossiblyLoopIndependent ,
3701+ CommonLevels);
36973702 ++TotalArrayPairs;
36983703
36993704 unsigned Pairs = 1 ;
@@ -4036,6 +4041,10 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
40364041 return nullptr ;
40374042 }
40384043
4044+ // Assert that we haven't added runtime assumptions when not allowed
4045+ assert (UnderRuntimeAssumptions || Assumptions.isAlwaysTrue ());
4046+
4047+ Result.Assumptions = getRuntimeAssumptions ();
40394048 return std::make_unique<FullDependence>(std::move (Result));
40404049}
40414050
0 commit comments