@@ -700,7 +700,7 @@ class AccessAnalysis {
700700 // / loop, but we will have checks for those pointers we could analyze.
701701 bool canCheckPtrAtRT (RuntimePointerChecking &RtCheck, Loop *TheLoop,
702702 const DenseMap<Value *, const SCEV *> &Strides,
703- Value *&UncomputablePtr);
703+ Value *&UncomputablePtr, bool AllowPartial );
704704
705705 // / Goes over all memory accesses, checks whether a RT check is needed
706706 // / and builds sets of dependent accesses.
@@ -1185,8 +1185,8 @@ bool AccessAnalysis::createCheckForAccess(
11851185
11861186bool AccessAnalysis::canCheckPtrAtRT (
11871187 RuntimePointerChecking &RtCheck, Loop *TheLoop,
1188- const DenseMap<Value *, const SCEV *> &StridesMap,
1189- Value *&UncomputablePtr ) {
1188+ const DenseMap<Value *, const SCEV *> &StridesMap, Value *&UncomputablePtr,
1189+ bool AllowPartial ) {
11901190 // Find pointers with computable bounds. We are going to use this information
11911191 // to place a runtime bound check.
11921192 bool CanDoRT = true ;
@@ -1279,6 +1279,8 @@ bool AccessAnalysis::canCheckPtrAtRT(
12791279 /* Assume=*/ true )) {
12801280 CanDoAliasSetRT = false ;
12811281 UncomputablePtr = Access.getPointer ();
1282+ if (!AllowPartial)
1283+ break ;
12821284 }
12831285 }
12841286 }
@@ -1318,7 +1320,7 @@ bool AccessAnalysis::canCheckPtrAtRT(
13181320 }
13191321 }
13201322
1321- if (MayNeedRTCheck)
1323+ if (MayNeedRTCheck && (CanDoRT || AllowPartial) )
13221324 RtCheck.generateChecks (DepCands, IsDepCheckNeeded);
13231325
13241326 LLVM_DEBUG (dbgs () << " LAA: We need to do " << RtCheck.getNumberOfChecks ()
@@ -1331,6 +1333,8 @@ bool AccessAnalysis::canCheckPtrAtRT(
13311333 bool CanDoRTIfNeeded = !RtCheck.Need || CanDoRT;
13321334 assert (CanDoRTIfNeeded == (CanDoRT || !MayNeedRTCheck) &&
13331335 " CanDoRTIfNeeded depends on RtCheck.Need" );
1336+ if (!CanDoRTIfNeeded && !AllowPartial)
1337+ RtCheck.reset ();
13341338 return CanDoRTIfNeeded;
13351339}
13361340
@@ -2600,7 +2604,7 @@ bool LoopAccessInfo::analyzeLoop(AAResults *AA, const LoopInfo *LI,
26002604 // to place a runtime bound check.
26012605 Value *UncomputablePtr = nullptr ;
26022606 HasCompletePtrRtChecking = Accesses.canCheckPtrAtRT (
2603- *PtrRtChecking, TheLoop, SymbolicStrides, UncomputablePtr);
2607+ *PtrRtChecking, TheLoop, SymbolicStrides, UncomputablePtr, AllowPartial );
26042608 if (!HasCompletePtrRtChecking) {
26052609 const auto *I = dyn_cast_or_null<Instruction>(UncomputablePtr);
26062610 recordAnalysis (" CantIdentifyArrayBounds" , I)
@@ -2629,8 +2633,9 @@ bool LoopAccessInfo::analyzeLoop(AAResults *AA, const LoopInfo *LI,
26292633 PtrRtChecking->Need = true ;
26302634
26312635 UncomputablePtr = nullptr ;
2632- HasCompletePtrRtChecking = Accesses.canCheckPtrAtRT (
2633- *PtrRtChecking, TheLoop, SymbolicStrides, UncomputablePtr);
2636+ HasCompletePtrRtChecking =
2637+ Accesses.canCheckPtrAtRT (*PtrRtChecking, TheLoop, SymbolicStrides,
2638+ UncomputablePtr, AllowPartial);
26342639
26352640 // Check that we found the bounds for the pointer.
26362641 if (!HasCompletePtrRtChecking) {
@@ -2908,9 +2913,10 @@ void LoopAccessInfo::collectStridedAccess(Value *MemAccess) {
29082913LoopAccessInfo::LoopAccessInfo (Loop *L, ScalarEvolution *SE,
29092914 const TargetTransformInfo *TTI,
29102915 const TargetLibraryInfo *TLI, AAResults *AA,
2911- DominatorTree *DT, LoopInfo *LI)
2916+ DominatorTree *DT, LoopInfo *LI,
2917+ bool AllowPartial)
29122918 : PSE(std::make_unique<PredicatedScalarEvolution>(*SE, *L)),
2913- PtrRtChecking (nullptr ), TheLoop(L) {
2919+ PtrRtChecking (nullptr ), TheLoop(L), AllowPartial(AllowPartial) {
29142920 unsigned MaxTargetVectorWidthInBits = std::numeric_limits<unsigned >::max ();
29152921 if (TTI && !TTI->enableScalableVectorization ())
29162922 // Scale the vector width by 2 as rough estimate to also consider
@@ -2980,12 +2986,15 @@ void LoopAccessInfo::print(raw_ostream &OS, unsigned Depth) const {
29802986 PSE->print (OS, Depth);
29812987}
29822988
2983- const LoopAccessInfo &LoopAccessInfoManager::getInfo (Loop &L) {
2989+ const LoopAccessInfo &LoopAccessInfoManager::getInfo (Loop &L,
2990+ bool AllowPartial) {
29842991 const auto &[It, Inserted] = LoopAccessInfoMap.try_emplace (&L);
29852992
2986- if (Inserted)
2987- It->second =
2988- std::make_unique<LoopAccessInfo>(&L, &SE, TTI, TLI, &AA, &DT, &LI);
2993+ // We need to create the LoopAccessInfo if either we don't already have one,
2994+ // or if it was created with a different value of AllowPartial.
2995+ if (Inserted || It->second ->hasAllowPartial () != AllowPartial)
2996+ It->second = std::make_unique<LoopAccessInfo>(&L, &SE, TTI, TLI, &AA, &DT,
2997+ &LI, AllowPartial);
29892998
29902999 return *It->second ;
29913000}
0 commit comments