@@ -250,62 +250,51 @@ void RuntimePointerChecking::insert(Loop *Lp, Value *Ptr, const SCEV *PtrExpr,
250
250
NeedsFreeze);
251
251
}
252
252
253
- void RuntimePointerChecking::tryToCreateDiffCheck (
253
+ bool RuntimePointerChecking::tryToCreateDiffCheck (
254
254
const RuntimeCheckingPtrGroup &CGI, const RuntimeCheckingPtrGroup &CGJ) {
255
- if (!CanUseDiffCheck)
256
- return ;
257
-
258
255
// If either group contains multiple different pointers, bail out.
259
256
// TODO: Support multiple pointers by using the minimum or maximum pointer,
260
257
// depending on src & sink.
261
- if (CGI.Members .size () != 1 || CGJ.Members .size () != 1 ) {
262
- CanUseDiffCheck = false ;
263
- return ;
264
- }
258
+ if (CGI.Members .size () != 1 || CGJ.Members .size () != 1 )
259
+ return false ;
265
260
266
261
PointerInfo *Src = &Pointers[CGI.Members [0 ]];
267
262
PointerInfo *Sink = &Pointers[CGJ.Members [0 ]];
268
263
269
264
// If either pointer is read and written, multiple checks may be needed. Bail
270
265
// out.
271
266
if (!DC.getOrderForAccess (Src->PointerValue , !Src->IsWritePtr ).empty () ||
272
- !DC.getOrderForAccess (Sink->PointerValue , !Sink->IsWritePtr ).empty ()) {
273
- CanUseDiffCheck = false ;
274
- return ;
275
- }
267
+ !DC.getOrderForAccess (Sink->PointerValue , !Sink->IsWritePtr ).empty ())
268
+ return false ;
276
269
277
270
ArrayRef<unsigned > AccSrc =
278
271
DC.getOrderForAccess (Src->PointerValue , Src->IsWritePtr );
279
272
ArrayRef<unsigned > AccSink =
280
273
DC.getOrderForAccess (Sink->PointerValue , Sink->IsWritePtr );
281
274
// If either pointer is accessed multiple times, there may not be a clear
282
275
// src/sink relation. Bail out for now.
283
- if (AccSrc.size () != 1 || AccSink.size () != 1 ) {
284
- CanUseDiffCheck = false ;
285
- return ;
286
- }
276
+ if (AccSrc.size () != 1 || AccSink.size () != 1 )
277
+ return false ;
278
+
287
279
// If the sink is accessed before src, swap src/sink.
288
280
if (AccSink[0 ] < AccSrc[0 ])
289
281
std::swap (Src, Sink);
290
282
291
283
auto *SrcAR = dyn_cast<SCEVAddRecExpr>(Src->Expr );
292
284
auto *SinkAR = dyn_cast<SCEVAddRecExpr>(Sink->Expr );
293
285
if (!SrcAR || !SinkAR || SrcAR->getLoop () != DC.getInnermostLoop () ||
294
- SinkAR->getLoop () != DC.getInnermostLoop ()) {
295
- CanUseDiffCheck = false ;
296
- return ;
297
- }
286
+ SinkAR->getLoop () != DC.getInnermostLoop ())
287
+ return false ;
298
288
299
289
SmallVector<Instruction *, 4 > SrcInsts =
300
290
DC.getInstructionsForAccess (Src->PointerValue , Src->IsWritePtr );
301
291
SmallVector<Instruction *, 4 > SinkInsts =
302
292
DC.getInstructionsForAccess (Sink->PointerValue , Sink->IsWritePtr );
303
293
Type *SrcTy = getLoadStoreType (SrcInsts[0 ]);
304
294
Type *DstTy = getLoadStoreType (SinkInsts[0 ]);
305
- if (isa<ScalableVectorType>(SrcTy) || isa<ScalableVectorType>(DstTy)) {
306
- CanUseDiffCheck = false ;
307
- return ;
308
- }
295
+ if (isa<ScalableVectorType>(SrcTy) || isa<ScalableVectorType>(DstTy))
296
+ return false ;
297
+
309
298
const DataLayout &DL =
310
299
SinkAR->getLoop ()->getHeader ()->getModule ()->getDataLayout ();
311
300
unsigned AllocSize =
@@ -316,10 +305,8 @@ void RuntimePointerChecking::tryToCreateDiffCheck(
316
305
// future.
317
306
auto *Step = dyn_cast<SCEVConstant>(SinkAR->getStepRecurrence (*SE));
318
307
if (!Step || Step != SrcAR->getStepRecurrence (*SE) ||
319
- Step->getAPInt ().abs () != AllocSize) {
320
- CanUseDiffCheck = false ;
321
- return ;
322
- }
308
+ Step->getAPInt ().abs () != AllocSize)
309
+ return false ;
323
310
324
311
IntegerType *IntTy =
325
312
IntegerType::get (Src->PointerValue ->getContext (),
@@ -332,10 +319,8 @@ void RuntimePointerChecking::tryToCreateDiffCheck(
332
319
const SCEV *SinkStartInt = SE->getPtrToIntExpr (SinkAR->getStart (), IntTy);
333
320
const SCEV *SrcStartInt = SE->getPtrToIntExpr (SrcAR->getStart (), IntTy);
334
321
if (isa<SCEVCouldNotCompute>(SinkStartInt) ||
335
- isa<SCEVCouldNotCompute>(SrcStartInt)) {
336
- CanUseDiffCheck = false ;
337
- return ;
338
- }
322
+ isa<SCEVCouldNotCompute>(SrcStartInt))
323
+ return false ;
339
324
340
325
const Loop *InnerLoop = SrcAR->getLoop ();
341
326
// If the start values for both Src and Sink also vary according to an outer
@@ -356,8 +341,7 @@ void RuntimePointerChecking::tryToCreateDiffCheck(
356
341
SinkStartAR->getStepRecurrence (*SE)) {
357
342
LLVM_DEBUG (dbgs () << " LAA: Not creating diff runtime check, since these "
358
343
" cannot be hoisted out of the outer loop\n " );
359
- CanUseDiffCheck = false ;
360
- return ;
344
+ return false ;
361
345
}
362
346
}
363
347
@@ -366,6 +350,7 @@ void RuntimePointerChecking::tryToCreateDiffCheck(
366
350
<< " SinkStartInt: " << *SinkStartInt << ' \n ' );
367
351
DiffChecks.emplace_back (SrcStartInt, SinkStartInt, AllocSize,
368
352
Src->NeedsFreeze || Sink->NeedsFreeze );
353
+ return true ;
369
354
}
370
355
371
356
SmallVector<RuntimePointerCheck, 4 > RuntimePointerChecking::generateChecks () {
@@ -377,7 +362,7 @@ SmallVector<RuntimePointerCheck, 4> RuntimePointerChecking::generateChecks() {
377
362
const RuntimeCheckingPtrGroup &CGJ = CheckingGroups[J];
378
363
379
364
if (needsChecking (CGI, CGJ)) {
380
- tryToCreateDiffCheck (CGI, CGJ);
365
+ CanUseDiffCheck = CanUseDiffCheck && tryToCreateDiffCheck (CGI, CGJ);
381
366
Checks.push_back (std::make_pair (&CGI, &CGJ));
382
367
}
383
368
}
@@ -394,9 +379,9 @@ void RuntimePointerChecking::generateChecks(
394
379
395
380
bool RuntimePointerChecking::needsChecking (
396
381
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] ))
382
+ for (auto &I : M.Members )
383
+ for (auto &J : N.Members )
384
+ if (needsChecking (I, J ))
400
385
return true ;
401
386
return false ;
402
387
}
@@ -410,9 +395,7 @@ static const SCEV *getMinFromExprs(const SCEV *I, const SCEV *J,
410
395
411
396
if (!C)
412
397
return nullptr ;
413
- if (C->getValue ()->isNegative ())
414
- return J;
415
- return I;
398
+ return C->getValue ()->isNegative () ? J : I;
416
399
}
417
400
418
401
bool RuntimeCheckingPtrGroup::addPointer (unsigned Index,
@@ -1646,22 +1629,19 @@ bool llvm::sortPtrAccesses(ArrayRef<Value *> VL, Type *ElemTy,
1646
1629
1647
1630
// Check if the pointer with the same offset is found.
1648
1631
int64_t Offset = *Diff;
1649
- auto Res = Offsets.emplace (Offset, Cnt);
1650
- if (!Res. second )
1632
+ auto [It, IsInserted] = Offsets.emplace (Offset, Cnt);
1633
+ if (!IsInserted )
1651
1634
return false ;
1652
1635
// Consecutive order if the inserted element is the last one.
1653
- IsConsecutive = IsConsecutive && std::next (Res. first ) == Offsets.end ();
1636
+ IsConsecutive = IsConsecutive && std::next (It ) == Offsets.end ();
1654
1637
++Cnt;
1655
1638
}
1656
1639
SortedIndices.clear ();
1657
1640
if (!IsConsecutive) {
1658
1641
// Fill SortedIndices array only if it is non-consecutive.
1659
1642
SortedIndices.resize (VL.size ());
1660
- Cnt = 0 ;
1661
- for (const std::pair<int64_t , int > &Pair : Offsets) {
1662
- SortedIndices[Cnt] = Pair.second ;
1663
- ++Cnt;
1664
- }
1643
+ for (const std::pair<int64_t , int > &Pair : Offsets)
1644
+ SortedIndices.push_back (Pair.second );
1665
1645
}
1666
1646
return true ;
1667
1647
}
@@ -1866,10 +1846,7 @@ static bool isSafeDependenceDistance(const DataLayout &DL, ScalarEvolution &SE,
1866
1846
// (If so, then we have proven (**) because |Dist| >= -1*Dist)
1867
1847
const SCEV *NegDist = SE.getNegativeSCEV (CastedDist);
1868
1848
Minus = SE.getMinusSCEV (NegDist, CastedProduct);
1869
- if (SE.isKnownPositive (Minus))
1870
- return true ;
1871
-
1872
- return false ;
1849
+ return SE.isKnownPositive (Minus);
1873
1850
}
1874
1851
1875
1852
// / Check the dependence for two accesses with the same stride \p Stride.
@@ -2043,7 +2020,7 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
2043
2020
if (isa<SCEVCouldNotCompute>(Dist)) {
2044
2021
// TODO: Relax requirement that there is a common stride to retry with
2045
2022
// non-constant distance dependencies.
2046
- FoundNonConstantDistanceDependence |= !! CommonStride;
2023
+ FoundNonConstantDistanceDependence |= CommonStride. has_value () ;
2047
2024
LLVM_DEBUG (dbgs () << " LAA: Dependence because of uncomputable distance.\n " );
2048
2025
return Dependence::Unknown;
2049
2026
}
@@ -2082,14 +2059,12 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
2082
2059
// Negative distances are not plausible dependencies.
2083
2060
if (SE.isKnownNonPositive (Dist)) {
2084
2061
if (SE.isKnownNonNegative (Dist)) {
2085
- if (HasSameSize) {
2062
+ if (HasSameSize)
2086
2063
// Write to the same location with the same size.
2087
2064
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
- }
2065
+ LLVM_DEBUG (dbgs () << " LAA: possibly zero dependence difference but "
2066
+ " different type sizes\n " );
2067
+ return Dependence::Unknown;
2093
2068
}
2094
2069
2095
2070
bool IsTrueDataDependence = (AIsWrite && !BIsWrite);
@@ -2335,7 +2310,7 @@ bool MemoryDepChecker::areDepsSafe(
2335
2310
}
2336
2311
++OI;
2337
2312
}
2338
- AI++ ;
2313
+ ++AI ;
2339
2314
}
2340
2315
}
2341
2316
@@ -2344,8 +2319,8 @@ bool MemoryDepChecker::areDepsSafe(
2344
2319
}
2345
2320
2346
2321
SmallVector<Instruction *, 4 >
2347
- MemoryDepChecker::getInstructionsForAccess (Value *Ptr, bool isWrite ) const {
2348
- MemAccessInfo Access (Ptr, isWrite );
2322
+ MemoryDepChecker::getInstructionsForAccess (Value *Ptr, bool IsWrite ) const {
2323
+ MemAccessInfo Access (Ptr, IsWrite );
2349
2324
auto &IndexVector = Accesses.find (Access)->second ;
2350
2325
2351
2326
SmallVector<Instruction *, 4 > Insts;
@@ -2656,7 +2631,7 @@ void LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI,
2656
2631
SymbolicStrides, UncomputablePtr, false );
2657
2632
if (!CanDoRTIfNeeded) {
2658
2633
auto *I = dyn_cast_or_null<Instruction>(UncomputablePtr);
2659
- recordAnalysis (" CantIdentifyArrayBounds" , I)
2634
+ recordAnalysis (" CantIdentifyArrayBounds" , I)
2660
2635
<< " cannot identify array bounds" ;
2661
2636
LLVM_DEBUG (dbgs () << " LAA: We can't vectorize because we can't find "
2662
2637
<< " the array bounds.\n " );
@@ -3050,11 +3025,10 @@ LoopAccessInfo::LoopAccessInfo(Loop *L, ScalarEvolution *SE,
3050
3025
if (TTI) {
3051
3026
TypeSize FixedWidth =
3052
3027
TTI->getRegisterBitWidth (TargetTransformInfo::RGK_FixedWidthVector);
3053
- if (FixedWidth.isNonZero ()) {
3028
+ if (FixedWidth.isNonZero ())
3054
3029
// Scale the vector width by 2 as rough estimate to also consider
3055
3030
// interleaving.
3056
3031
MaxTargetVectorWidthInBits = FixedWidth.getFixedValue () * 2 ;
3057
- }
3058
3032
3059
3033
TypeSize ScalableWidth =
3060
3034
TTI->getRegisterBitWidth (TargetTransformInfo::RGK_ScalableVector);
@@ -3064,9 +3038,8 @@ LoopAccessInfo::LoopAccessInfo(Loop *L, ScalarEvolution *SE,
3064
3038
DepChecker =
3065
3039
std::make_unique<MemoryDepChecker>(*PSE, L, MaxTargetVectorWidthInBits);
3066
3040
PtrRtChecking = std::make_unique<RuntimePointerChecking>(*DepChecker, SE);
3067
- if (canAnalyzeLoop ()) {
3041
+ if (canAnalyzeLoop ())
3068
3042
analyzeLoop (AA, LI, TLI, DT);
3069
- }
3070
3043
}
3071
3044
3072
3045
void LoopAccessInfo::print (raw_ostream &OS, unsigned Depth) const {
0 commit comments