Skip to content

Commit 9aae1c7

Browse files
committed
Re-add code for invariant pointers
1 parent 1cbff93 commit 9aae1c7

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
@@ -276,8 +276,20 @@ static bool AreEquivalentAddressValues(const Value *A, const Value *B) {
276276
bool llvm::isDereferenceableAndAlignedInLoop(
277277
LoadInst *LI, Loop *L, ScalarEvolution &SE, DominatorTree &DT,
278278
AssumptionCache *AC, SmallVectorImpl<const SCEVPredicate *> *Predicates) {
279-
const SCEV *Ptr = SE.getSCEV(LI->getPointerOperand());
280-
auto *AddRec = dyn_cast<SCEVAddRecExpr>(Ptr);
279+
const Align Alignment = LI->getAlign();
280+
auto &DL = LI->getDataLayout();
281+
Value *Ptr = LI->getPointerOperand();
282+
APInt EltSize(DL.getIndexTypeSizeInBits(Ptr->getType()),
283+
DL.getTypeStoreSize(LI->getType()).getFixedValue());
284+
285+
// If given a uniform (i.e. non-varying) address, see if we can prove the
286+
// access is safe within the loop w/o needing predication.
287+
if (L->isLoopInvariant(Ptr))
288+
return isDereferenceableAndAlignedPointer(
289+
Ptr, Alignment, EltSize, DL, L->getHeader()->getFirstNonPHI(), AC, &DT);
290+
291+
const SCEV *PtrScev = SE.getSCEV(Ptr);
292+
auto *AddRec = dyn_cast<SCEVAddRecExpr>(PtrScev);
281293

282294
// Check to see if we have a repeating access pattern and it's possible
283295
// to prove all accesses are well aligned.
@@ -291,10 +303,6 @@ bool llvm::isDereferenceableAndAlignedInLoop(
291303
// For the moment, restrict ourselves to the case where the access size is a
292304
// multiple of the requested alignment and the base is aligned.
293305
// TODO: generalize if a case found which warrants
294-
const Align Alignment = LI->getAlign();
295-
auto &DL = LI->getDataLayout();
296-
APInt EltSize(DL.getIndexTypeSizeInBits(Ptr->getType()),
297-
DL.getTypeStoreSize(LI->getType()).getFixedValue());
298306
if (EltSize.urem(Alignment.value()) != 0)
299307
return false;
300308

@@ -307,8 +315,8 @@ bool llvm::isDereferenceableAndAlignedInLoop(
307315
if (isa<SCEVCouldNotCompute>(MaxBECount))
308316
return false;
309317

310-
const auto &[AccessStart, AccessEnd] =
311-
getStartAndEndForAccess(L, Ptr, LI->getType(), MaxBECount, &SE, nullptr);
318+
const auto &[AccessStart, AccessEnd] = getStartAndEndForAccess(
319+
L, PtrScev, LI->getType(), MaxBECount, &SE, nullptr);
312320
if (isa<SCEVCouldNotCompute>(AccessStart) ||
313321
isa<SCEVCouldNotCompute>(AccessEnd))
314322
return false;

0 commit comments

Comments
 (0)