Skip to content

Commit 78cf109

Browse files
committed
Re-add code for invariant pointers
1 parent 2d5510f commit 78cf109

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

llvm/lib/Analysis/Loads.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,20 @@ static bool AreEquivalentAddressValues(const Value *A, const Value *B) {
277277
bool llvm::isDereferenceableAndAlignedInLoop(
278278
LoadInst *LI, Loop *L, ScalarEvolution &SE, DominatorTree &DT,
279279
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);
282294

283295
// Check to see if we have a repeating access pattern and it's possible
284296
// to prove all accesses are well aligned.
@@ -292,10 +304,6 @@ bool llvm::isDereferenceableAndAlignedInLoop(
292304
// For the moment, restrict ourselves to the case where the access size is a
293305
// multiple of the requested alignment and the base is aligned.
294306
// 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());
299307
if (EltSize.urem(Alignment.value()) != 0)
300308
return false;
301309

@@ -308,8 +316,8 @@ bool llvm::isDereferenceableAndAlignedInLoop(
308316
if (isa<SCEVCouldNotCompute>(MaxBECount))
309317
return false;
310318

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);
313321
if (isa<SCEVCouldNotCompute>(AccessStart) ||
314322
isa<SCEVCouldNotCompute>(AccessEnd))
315323
return false;

0 commit comments

Comments
 (0)