@@ -394,9 +394,9 @@ void RuntimePointerChecking::generateChecks(
394
394
395
395
bool RuntimePointerChecking::needsChecking (
396
396
const RuntimeCheckingPtrGroup &M, const RuntimeCheckingPtrGroup &N) const {
397
- for (unsigned I = 0 , EI = M.Members . size (); EI != I; ++I )
398
- for (unsigned J = 0 , EJ = N.Members . size (); EJ != J; ++J )
399
- if (needsChecking (M. Members [I], N. Members [J] ))
397
+ for (auto &I : M.Members )
398
+ for (auto &J : N.Members )
399
+ if (needsChecking (I, J ))
400
400
return true ;
401
401
return false ;
402
402
}
@@ -410,9 +410,7 @@ static const SCEV *getMinFromExprs(const SCEV *I, const SCEV *J,
410
410
411
411
if (!C)
412
412
return nullptr ;
413
- if (C->getValue ()->isNegative ())
414
- return J;
415
- return I;
413
+ return C->getValue ()->isNegative () ? J : I;
416
414
}
417
415
418
416
bool RuntimeCheckingPtrGroup::addPointer (unsigned Index,
@@ -510,8 +508,8 @@ void RuntimePointerChecking::groupChecks(
510
508
511
509
DenseMap<Value *, SmallVector<unsigned >> PositionMap;
512
510
for (unsigned Index = 0 ; Index < Pointers.size (); ++Index) {
513
- auto Iter = PositionMap.insert ({Pointers[Index].PointerValue , {}});
514
- Iter. first ->second .push_back (Index);
511
+ auto [It, _] = PositionMap.insert ({Pointers[Index].PointerValue , {}});
512
+ It ->second .push_back (Index);
515
513
}
516
514
517
515
// We need to keep track of what pointers we've already seen so we
@@ -610,16 +608,16 @@ void RuntimePointerChecking::printChecks(
610
608
raw_ostream &OS, const SmallVectorImpl<RuntimePointerCheck> &Checks,
611
609
unsigned Depth) const {
612
610
unsigned N = 0 ;
613
- for (const auto &Check : Checks) {
614
- const auto &First = Check. first ->Members , &Second = Check. second ->Members ;
611
+ for (const auto &[Check1, Check2] : Checks) {
612
+ const auto &First = Check1 ->Members , &Second = Check2 ->Members ;
615
613
616
614
OS.indent (Depth) << " Check " << N++ << " :\n " ;
617
615
618
- OS.indent (Depth + 2 ) << " Comparing group (" << Check. first << " ):\n " ;
616
+ OS.indent (Depth + 2 ) << " Comparing group (" << Check1 << " ):\n " ;
619
617
for (unsigned K = 0 ; K < First.size (); ++K)
620
618
OS.indent (Depth + 2 ) << *Pointers[First[K]].PointerValue << " \n " ;
621
619
622
- OS.indent (Depth + 2 ) << " Against group (" << Check. second << " ):\n " ;
620
+ OS.indent (Depth + 2 ) << " Against group (" << Check2 << " ):\n " ;
623
621
for (unsigned K = 0 ; K < Second.size (); ++K)
624
622
OS.indent (Depth + 2 ) << *Pointers[Second[K]].PointerValue << " \n " ;
625
623
}
@@ -1160,8 +1158,8 @@ bool AccessAnalysis::canCheckPtrAtRT(RuntimePointerChecking &RtCheck,
1160
1158
// First, count how many write and read accesses are in the alias set. Also
1161
1159
// collect MemAccessInfos for later.
1162
1160
SmallVector<MemAccessInfo, 4 > AccessInfos;
1163
- for (const Value *Ptr_ : ASPointers) {
1164
- Value *Ptr = const_cast <Value *>(Ptr_ );
1161
+ for (const Value *ConstPtr : ASPointers) {
1162
+ Value *Ptr = const_cast <Value *>(ConstPtr );
1165
1163
bool IsWrite = Accesses.count (MemAccessInfo (Ptr, true ));
1166
1164
if (IsWrite)
1167
1165
++NumWritePtrChecks;
@@ -1217,9 +1215,7 @@ bool AccessAnalysis::canCheckPtrAtRT(RuntimePointerChecking &RtCheck,
1217
1215
// We know that we need these checks, so we can now be more aggressive
1218
1216
// and add further checks if required (overflow checks).
1219
1217
CanDoAliasSetRT = true ;
1220
- for (auto Retry : Retries) {
1221
- MemAccessInfo Access = Retry.first ;
1222
- Type *AccessTy = Retry.second ;
1218
+ for (const auto &[Access, AccessTy] : Retries) {
1223
1219
if (!createCheckForAccess (RtCheck, Access, AccessTy, StridesMap,
1224
1220
DepSetId, TheLoop, RunningDepId, ASId,
1225
1221
ShouldCheckWrap, /* Assume=*/ true )) {
@@ -1291,12 +1287,11 @@ void AccessAnalysis::processMemAccesses() {
1291
1287
LLVM_DEBUG (dbgs () << " AST: " ; AST.dump ());
1292
1288
LLVM_DEBUG (dbgs () << " LAA: Accesses(" << Accesses.size () << " ):\n " );
1293
1289
LLVM_DEBUG ({
1294
- for (auto A : Accesses)
1295
- dbgs () << " \t " << *A.first .getPointer () << " ("
1296
- << (A.first .getInt ()
1297
- ? " write"
1298
- : (ReadOnlyPtr.count (A.first .getPointer ()) ? " read-only"
1299
- : " read" ))
1290
+ for (const auto &[A, _] : Accesses)
1291
+ dbgs () << " \t " << *A.getPointer () << " ("
1292
+ << (A.getInt () ? " write"
1293
+ : (ReadOnlyPtr.count (A.getPointer ()) ? " read-only"
1294
+ : " read" ))
1300
1295
<< " )\n " ;
1301
1296
});
1302
1297
@@ -1325,16 +1320,16 @@ void AccessAnalysis::processMemAccesses() {
1325
1320
bool UseDeferred = SetIteration > 0 ;
1326
1321
PtrAccessMap &S = UseDeferred ? DeferredAccesses : Accesses;
1327
1322
1328
- for (const Value *Ptr_ : ASPointers) {
1329
- Value *Ptr = const_cast <Value *>(Ptr_ );
1323
+ for (const Value *ConstPtr : ASPointers) {
1324
+ Value *Ptr = const_cast <Value *>(ConstPtr );
1330
1325
1331
1326
// For a single memory access in AliasSetTracker, Accesses may contain
1332
1327
// both read and write, and they both need to be handled for CheckDeps.
1333
- for (const auto &AC : S) {
1334
- if (AC.first . getPointer () != Ptr)
1328
+ for (const auto &[AC, _] : S) {
1329
+ if (AC.getPointer () != Ptr)
1335
1330
continue ;
1336
1331
1337
- bool IsWrite = AC.first . getInt ();
1332
+ bool IsWrite = AC.getInt ();
1338
1333
1339
1334
// If we're using the deferred access set, then it contains only
1340
1335
// reads.
@@ -1866,10 +1861,7 @@ static bool isSafeDependenceDistance(const DataLayout &DL, ScalarEvolution &SE,
1866
1861
// (If so, then we have proven (**) because |Dist| >= -1*Dist)
1867
1862
const SCEV *NegDist = SE.getNegativeSCEV (CastedDist);
1868
1863
Minus = SE.getMinusSCEV (NegDist, CastedProduct);
1869
- if (SE.isKnownPositive (Minus))
1870
- return true ;
1871
-
1872
- return false ;
1864
+ return SE.isKnownPositive (Minus);
1873
1865
}
1874
1866
1875
1867
// / Check the dependence for two accesses with the same stride \p Stride.
@@ -2043,7 +2035,7 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
2043
2035
if (isa<SCEVCouldNotCompute>(Dist)) {
2044
2036
// TODO: Relax requirement that there is a common stride to retry with
2045
2037
// non-constant distance dependencies.
2046
- FoundNonConstantDistanceDependence |= !! CommonStride;
2038
+ FoundNonConstantDistanceDependence |= CommonStride. has_value () ;
2047
2039
LLVM_DEBUG (dbgs () << " LAA: Dependence because of uncomputable distance.\n " );
2048
2040
return Dependence::Unknown;
2049
2041
}
@@ -2082,14 +2074,12 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
2082
2074
// Negative distances are not plausible dependencies.
2083
2075
if (SE.isKnownNonPositive (Dist)) {
2084
2076
if (SE.isKnownNonNegative (Dist)) {
2085
- if (HasSameSize) {
2077
+ if (HasSameSize)
2086
2078
// Write to the same location with the same size.
2087
2079
return Dependence::Forward;
2088
- } else {
2089
- LLVM_DEBUG (dbgs () << " LAA: possibly zero dependence difference but "
2090
- " different type sizes\n " );
2091
- return Dependence::Unknown;
2092
- }
2080
+ LLVM_DEBUG (dbgs () << " LAA: possibly zero dependence difference but "
2081
+ " different type sizes\n " );
2082
+ return Dependence::Unknown;
2093
2083
}
2094
2084
2095
2085
bool IsTrueDataDependence = (AIsWrite && !BIsWrite);
@@ -2335,7 +2325,7 @@ bool MemoryDepChecker::areDepsSafe(
2335
2325
}
2336
2326
++OI;
2337
2327
}
2338
- AI++ ;
2328
+ ++AI ;
2339
2329
}
2340
2330
}
2341
2331
@@ -2344,8 +2334,8 @@ bool MemoryDepChecker::areDepsSafe(
2344
2334
}
2345
2335
2346
2336
SmallVector<Instruction *, 4 >
2347
- MemoryDepChecker::getInstructionsForAccess (Value *Ptr, bool isWrite ) const {
2348
- MemAccessInfo Access (Ptr, isWrite );
2337
+ MemoryDepChecker::getInstructionsForAccess (Value *Ptr, bool IsWrite ) const {
2338
+ MemAccessInfo Access (Ptr, IsWrite );
2349
2339
auto &IndexVector = Accesses.find (Access)->second ;
2350
2340
2351
2341
SmallVector<Instruction *, 4 > Insts;
@@ -2656,7 +2646,7 @@ void LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI,
2656
2646
SymbolicStrides, UncomputablePtr, false );
2657
2647
if (!CanDoRTIfNeeded) {
2658
2648
auto *I = dyn_cast_or_null<Instruction>(UncomputablePtr);
2659
- recordAnalysis (" CantIdentifyArrayBounds" , I)
2649
+ recordAnalysis (" CantIdentifyArrayBounds" , I)
2660
2650
<< " cannot identify array bounds" ;
2661
2651
LLVM_DEBUG (dbgs () << " LAA: We can't vectorize because we can't find "
2662
2652
<< " the array bounds.\n " );
@@ -2721,13 +2711,14 @@ void LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI,
2721
2711
}
2722
2712
2723
2713
void LoopAccessInfo::emitUnsafeDependenceRemark () {
2724
- auto Deps = getDepChecker ().getDependences ();
2714
+ const auto * Deps = getDepChecker ().getDependences ();
2725
2715
if (!Deps)
2726
2716
return ;
2727
- auto Found = llvm::find_if (*Deps, [](const MemoryDepChecker::Dependence &D) {
2728
- return MemoryDepChecker::Dependence::isSafeForVectorization (D.Type ) !=
2729
- MemoryDepChecker::VectorizationSafetyStatus::Safe;
2730
- });
2717
+ const auto *Found =
2718
+ llvm::find_if (*Deps, [](const MemoryDepChecker::Dependence &D) {
2719
+ return MemoryDepChecker::Dependence::isSafeForVectorization (D.Type ) !=
2720
+ MemoryDepChecker::VectorizationSafetyStatus::Safe;
2721
+ });
2731
2722
if (Found == Deps->end ())
2732
2723
return ;
2733
2724
MemoryDepChecker::Dependence Dep = *Found;
@@ -2866,9 +2857,9 @@ static Value *stripGetElementPtr(Value *Ptr, ScalarEvolution *SE, Loop *Lp) {
2866
2857
2867
2858
// Check that all of the gep indices are uniform except for our induction
2868
2859
// operand.
2869
- for (unsigned i = 0 , e = GEP->getNumOperands (); i != e ; ++i )
2870
- if (i != InductionOperand &&
2871
- !SE->isLoopInvariant (SE->getSCEV (GEP->getOperand (i )), Lp))
2860
+ for (unsigned I = 0 , E = GEP->getNumOperands (); I != E ; ++I )
2861
+ if (I != InductionOperand &&
2862
+ !SE->isLoopInvariant (SE->getSCEV (GEP->getOperand (I )), Lp))
2872
2863
return Ptr;
2873
2864
return GEP->getOperand (InductionOperand);
2874
2865
}
@@ -3050,11 +3041,10 @@ LoopAccessInfo::LoopAccessInfo(Loop *L, ScalarEvolution *SE,
3050
3041
if (TTI) {
3051
3042
TypeSize FixedWidth =
3052
3043
TTI->getRegisterBitWidth (TargetTransformInfo::RGK_FixedWidthVector);
3053
- if (FixedWidth.isNonZero ()) {
3044
+ if (FixedWidth.isNonZero ())
3054
3045
// Scale the vector width by 2 as rough estimate to also consider
3055
3046
// interleaving.
3056
3047
MaxTargetVectorWidthInBits = FixedWidth.getFixedValue () * 2 ;
3057
- }
3058
3048
3059
3049
TypeSize ScalableWidth =
3060
3050
TTI->getRegisterBitWidth (TargetTransformInfo::RGK_ScalableVector);
@@ -3064,9 +3054,8 @@ LoopAccessInfo::LoopAccessInfo(Loop *L, ScalarEvolution *SE,
3064
3054
DepChecker =
3065
3055
std::make_unique<MemoryDepChecker>(*PSE, L, MaxTargetVectorWidthInBits);
3066
3056
PtrRtChecking = std::make_unique<RuntimePointerChecking>(*DepChecker, SE);
3067
- if (canAnalyzeLoop ()) {
3057
+ if (canAnalyzeLoop ())
3068
3058
analyzeLoop (AA, LI, TLI, DT);
3069
- }
3070
3059
}
3071
3060
3072
3061
void LoopAccessInfo::print (raw_ostream &OS, unsigned Depth) const {
@@ -3118,13 +3107,13 @@ void LoopAccessInfo::print(raw_ostream &OS, unsigned Depth) const {
3118
3107
}
3119
3108
3120
3109
const LoopAccessInfo &LoopAccessInfoManager::getInfo (Loop &L) {
3121
- auto I = LoopAccessInfoMap.insert ({&L, nullptr });
3110
+ auto [It, Inserted] = LoopAccessInfoMap.insert ({&L, nullptr });
3122
3111
3123
- if (I. second )
3124
- I. first ->second =
3112
+ if (Inserted )
3113
+ It ->second =
3125
3114
std::make_unique<LoopAccessInfo>(&L, &SE, TTI, TLI, &AA, &DT, &LI);
3126
3115
3127
- return *I. first ->second ;
3116
+ return *It ->second ;
3128
3117
}
3129
3118
3130
3119
bool LoopAccessInfoManager::invalidate (
0 commit comments