@@ -269,9 +269,10 @@ bool Dependence::isScalar(unsigned level) const {
269
269
// FullDependence methods
270
270
271
271
FullDependence::FullDependence (Instruction *Source, Instruction *Destination,
272
+ const SCEVUnionPredicate &Assumes,
272
273
bool PossiblyLoopIndependent,
273
274
unsigned CommonLevels)
274
- : Dependence(Source, Destination), Levels(CommonLevels),
275
+ : Dependence(Source, Destination, Assumes ), Levels(CommonLevels),
275
276
LoopIndependent(PossiblyLoopIndependent) {
276
277
Consistent = true ;
277
278
if (CommonLevels)
@@ -711,6 +712,12 @@ void Dependence::dump(raw_ostream &OS) const {
711
712
OS << " splitable" ;
712
713
}
713
714
OS << " !\n " ;
715
+
716
+ SCEVUnionPredicate Assumptions = getRuntimeAssumptions ();
717
+ if (!Assumptions.isAlwaysTrue ()) {
718
+ OS << " Runtime Assumptions:\n " ;
719
+ Assumptions.print (OS, 2 );
720
+ }
714
721
}
715
722
716
723
// Returns NoAlias/MayAliass/MustAlias for two memory locations based upon their
@@ -3574,7 +3581,7 @@ bool DependenceInfo::invalidate(Function &F, const PreservedAnalyses &PA,
3574
3581
Inv.invalidate <LoopAnalysis>(F, PA);
3575
3582
}
3576
3583
3577
- SCEVUnionPredicate DependenceInfo::getRuntimeAssumptions () {
3584
+ SCEVUnionPredicate DependenceInfo::getRuntimeAssumptions () const {
3578
3585
return SCEVUnionPredicate (Assumptions, *SE);
3579
3586
}
3580
3587
@@ -3590,7 +3597,9 @@ SCEVUnionPredicate DependenceInfo::getRuntimeAssumptions() {
3590
3597
// Care is required to keep the routine below, getSplitIteration(),
3591
3598
// up to date with respect to this routine.
3592
3599
std::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;
3594
3603
bool PossiblyLoopIndependent = true ;
3595
3604
if (Src == Dst)
3596
3605
PossiblyLoopIndependent = false ;
@@ -3602,7 +3611,8 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst) {
3602
3611
if (!isLoadOrStore (Src) || !isLoadOrStore (Dst)) {
3603
3612
// can only analyze simple loads and stores, i.e., no calls, invokes, etc.
3604
3613
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));
3606
3616
}
3607
3617
3608
3618
const MemoryLocation &DstLoc = MemoryLocation::get (Dst);
@@ -3613,7 +3623,8 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst) {
3613
3623
case AliasResult::PartialAlias:
3614
3624
// cannot analyse objects if we don't understand their aliasing.
3615
3625
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));
3617
3628
case AliasResult::NoAlias:
3618
3629
// If the objects noalias, they are distinct, accesses are independent.
3619
3630
LLVM_DEBUG (dbgs () << " no alias\n " );
@@ -3626,7 +3637,8 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst) {
3626
3637
// The dependence test gets confused if the size of the memory accesses
3627
3638
// differ.
3628
3639
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));
3630
3642
}
3631
3643
3632
3644
Value *SrcPtr = getLoadStorePointerOperand (Src);
@@ -3645,7 +3657,8 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst) {
3645
3657
// We check this upfront so we don't crash in cases where getMinusSCEV()
3646
3658
// returns a SCEVCouldNotCompute.
3647
3659
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));
3649
3662
}
3650
3663
3651
3664
uint64_t EltSize = SrcLoc.Size .toRaw ();
@@ -3656,18 +3669,40 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst) {
3656
3669
3657
3670
if (Src != Dst) {
3658
3671
// 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 )) {
3661
3674
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
+ }
3663
3697
}
3664
3698
}
3665
3699
3666
3700
establishNestingLevels (Src, Dst);
3667
3701
LLVM_DEBUG (dbgs () << " common nesting levels = " << CommonLevels << " \n " );
3668
3702
LLVM_DEBUG (dbgs () << " maximum nesting levels = " << MaxLevels << " \n " );
3669
3703
3670
- FullDependence Result (Src, Dst, PossiblyLoopIndependent, CommonLevels);
3704
+ FullDependence Result (Src, Dst, SCEVUnionPredicate (Assume, *SE),
3705
+ PossiblyLoopIndependent, CommonLevels);
3671
3706
++TotalArrayPairs;
3672
3707
3673
3708
unsigned Pairs = 1 ;
@@ -4065,7 +4100,7 @@ const SCEV *DependenceInfo::getSplitIteration(const Dependence &Dep,
4065
4100
// establish loop nesting levels
4066
4101
establishNestingLevels (Src, Dst);
4067
4102
4068
- FullDependence Result (Src, Dst, false , CommonLevels);
4103
+ FullDependence Result (Src, Dst, Dep. Assumptions , false , CommonLevels);
4069
4104
4070
4105
unsigned Pairs = 1 ;
4071
4106
SmallVector<Subscript, 2 > Pair (Pairs);
0 commit comments