@@ -277,8 +277,20 @@ static bool AreEquivalentAddressValues(const Value *A, const Value *B) {
277
277
bool llvm::isDereferenceableAndAlignedInLoop (
278
278
LoadInst *LI, Loop *L, ScalarEvolution &SE, DominatorTree &DT,
279
279
AssumptionCache *AC, SmallVectorImpl<const SCEVPredicate *> *Predicates) {
280
- const SCEV *Ptr = SE.getSCEV (LI->getPointerOperand ());
281
- auto *AddRec = dyn_cast<SCEVAddRecExpr>(Ptr );
280
+ const Align Alignment = LI->getAlign ();
281
+ auto &DL = LI->getDataLayout ();
282
+ Value *Ptr = LI->getPointerOperand ();
283
+ APInt EltSize (DL.getIndexTypeSizeInBits (Ptr ->getType ()),
284
+ DL.getTypeStoreSize (LI->getType ()).getFixedValue ());
285
+
286
+ // If given a uniform (i.e. non-varying) address, see if we can prove the
287
+ // access is safe within the loop w/o needing predication.
288
+ if (L->isLoopInvariant (Ptr ))
289
+ return isDereferenceableAndAlignedPointer (
290
+ Ptr , Alignment, EltSize, DL, L->getHeader ()->getFirstNonPHI (), AC, &DT);
291
+
292
+ const SCEV *PtrScev = SE.getSCEV (Ptr );
293
+ auto *AddRec = dyn_cast<SCEVAddRecExpr>(PtrScev);
282
294
283
295
// Check to see if we have a repeating access pattern and it's possible
284
296
// to prove all accesses are well aligned.
@@ -292,10 +304,6 @@ bool llvm::isDereferenceableAndAlignedInLoop(
292
304
// For the moment, restrict ourselves to the case where the access size is a
293
305
// multiple of the requested alignment and the base is aligned.
294
306
// TODO: generalize if a case found which warrants
295
- const Align Alignment = LI->getAlign ();
296
- auto &DL = LI->getDataLayout ();
297
- APInt EltSize (DL.getIndexTypeSizeInBits (Ptr ->getType ()),
298
- DL.getTypeStoreSize (LI->getType ()).getFixedValue ());
299
307
if (EltSize.urem (Alignment.value ()) != 0 )
300
308
return false ;
301
309
@@ -308,8 +316,8 @@ bool llvm::isDereferenceableAndAlignedInLoop(
308
316
if (isa<SCEVCouldNotCompute>(MaxBECount))
309
317
return false ;
310
318
311
- const auto &[AccessStart, AccessEnd] =
312
- getStartAndEndForAccess ( L, Ptr , LI->getType (), MaxBECount, &SE, nullptr );
319
+ const auto &[AccessStart, AccessEnd] = getStartAndEndForAccess (
320
+ L, PtrScev , LI->getType (), MaxBECount, &SE, nullptr );
313
321
if (isa<SCEVCouldNotCompute>(AccessStart) ||
314
322
isa<SCEVCouldNotCompute>(AccessEnd))
315
323
return false ;
0 commit comments