Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions llvm/include/llvm/Analysis/Delinearization.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ bool delinearizeFixedSizeArray(ScalarEvolution &SE, const SCEV *Expr,
///
/// This function optimistically assumes the GEP references into a fixed size
/// array. If this is actually true, this function returns a list of array
/// subscript expressions in \p Subscripts and a list of integers describing
/// the size of the individual array dimensions in \p Sizes. Both lists have
/// either equal length or the size list is one element shorter in case there
/// is no known size available for the outermost array dimension. Returns true
/// if successful and false otherwise.
/// subscript expressions in \p Subscripts and a list of SCEV expressions
/// describing the size of the individual array dimensions in \p Sizes. Both
/// lists have either equal length or the size list is one element shorter in
/// case there is no known size available for the outermost array dimension.
/// Returns true if successful and false otherwise.
bool getIndexExpressionsFromGEP(ScalarEvolution &SE,
const GetElementPtrInst *GEP,
SmallVectorImpl<const SCEV *> &Subscripts,
SmallVectorImpl<int> &Sizes);
SmallVectorImpl<const SCEV *> &Sizes);

/// Implementation of fixed size array delinearization. Try to delinearize
/// access function for a fixed size multi-dimensional array, by deriving
Expand All @@ -164,7 +164,7 @@ bool getIndexExpressionsFromGEP(ScalarEvolution &SE,
bool tryDelinearizeFixedSizeImpl(ScalarEvolution *SE, Instruction *Inst,
const SCEV *AccessFn,
SmallVectorImpl<const SCEV *> &Subscripts,
SmallVectorImpl<int> &Sizes);
SmallVectorImpl<const SCEV *> &Sizes);

struct DelinearizationPrinterPass
: public PassInfoMixin<DelinearizationPrinterPass> {
Expand Down
7 changes: 4 additions & 3 deletions llvm/lib/Analysis/Delinearization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ bool llvm::delinearizeFixedSizeArray(ScalarEvolution &SE, const SCEV *Expr,
bool llvm::getIndexExpressionsFromGEP(ScalarEvolution &SE,
const GetElementPtrInst *GEP,
SmallVectorImpl<const SCEV *> &Subscripts,
SmallVectorImpl<int> &Sizes) {
SmallVectorImpl<const SCEV *> &Sizes) {
assert(Subscripts.empty() && Sizes.empty() &&
"Expected output lists to be empty on entry to this function.");
assert(GEP && "getIndexExpressionsFromGEP called with a null GEP");
Expand Down Expand Up @@ -690,7 +690,8 @@ bool llvm::getIndexExpressionsFromGEP(ScalarEvolution &SE,

Subscripts.push_back(Expr);
if (!(DroppedFirstDim && i == 2))
Sizes.push_back(ArrayTy->getNumElements());
Sizes.push_back(SE.getConstant(Expr->getType(),
ArrayTy->getNumElements()));
Comment on lines +693 to +694
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as #156342 (comment), maybe using DataLayout::getIndexSize is better.


Ty = ArrayTy->getElementType();
}
Expand All @@ -706,7 +707,7 @@ bool llvm::getIndexExpressionsFromGEP(ScalarEvolution &SE,

bool llvm::tryDelinearizeFixedSizeImpl(
ScalarEvolution *SE, Instruction *Inst, const SCEV *AccessFn,
SmallVectorImpl<const SCEV *> &Subscripts, SmallVectorImpl<int> &Sizes) {
SmallVectorImpl<const SCEV *> &Subscripts, SmallVectorImpl<const SCEV *> &Sizes) {
Value *SrcPtr = getLoadStorePointerOperand(Inst);

// Check the simple case where the array dimensions are fixed size.
Expand Down
27 changes: 12 additions & 15 deletions llvm/lib/Analysis/DependenceAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3504,16 +3504,16 @@ bool DependenceInfo::tryDelinearizeFixedSize(
"expected src and dst scev unknowns to be equal");
});

SmallVector<int, 4> SrcSizes;
SmallVector<int, 4> DstSizes;
SmallVector<const SCEV *, 4> SrcSizes;
SmallVector<const SCEV *, 4> DstSizes;
if (!tryDelinearizeFixedSizeImpl(SE, Src, SrcAccessFn, SrcSubscripts,
SrcSizes) ||
!tryDelinearizeFixedSizeImpl(SE, Dst, DstAccessFn, DstSubscripts,
DstSizes))
return false;

// Check that the two size arrays are non-empty and equal in length and
// value.
// value. SCEV expressions are uniqued, so we can compare pointers.
if (SrcSizes.size() != DstSizes.size() ||
!std::equal(SrcSizes.begin(), SrcSizes.end(), DstSizes.begin())) {
SrcSubscripts.clear();
Expand All @@ -3535,7 +3535,7 @@ bool DependenceInfo::tryDelinearizeFixedSize(
// iff the subscripts are positive and are less than the range of the
// dimension.
if (!DisableDelinearizationChecks) {
auto AllIndicesInRange = [&](SmallVector<int, 4> &DimensionSizes,
auto AllIndicesInRange = [&](SmallVector<const SCEV *, 4> &DimensionSizes,
SmallVectorImpl<const SCEV *> &Subscripts,
Value *Ptr) {
size_t SSize = Subscripts.size();
Expand All @@ -3548,17 +3548,14 @@ bool DependenceInfo::tryDelinearizeFixedSize(
});
return false;
}
if (auto *SType = dyn_cast<IntegerType>(S->getType())) {
const SCEV *Range = SE->getConstant(
ConstantInt::get(SType, DimensionSizes[I - 1], false));
if (!isKnownLessThan(S, Range)) {
LLVM_DEBUG({
dbgs() << "Check failed: !isKnownLessThan(S, Range)\n";
dbgs() << " S: " << *S << "\n"
<< " Range: " << *Range << "\n";
});
return false;
}
const SCEV *Range = DimensionSizes[I - 1];
if (!isKnownLessThan(S, Range)) {
LLVM_DEBUG({
dbgs() << "Check failed: !isKnownLessThan(S, Range)\n";
dbgs() << " S: " << *S << "\n"
<< " Range: " << *Range << "\n";
});
return false;
}
}
return true;
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Analysis/LoopCacheAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,14 @@ CacheCostTy IndexedReference::computeRefCost(const Loop &L,

bool IndexedReference::tryDelinearizeFixedSize(
const SCEV *AccessFn, SmallVectorImpl<const SCEV *> &Subscripts) {
SmallVector<int, 4> ArraySizes;
SmallVector<const SCEV *, 4> ArraySizes;
if (!tryDelinearizeFixedSizeImpl(&SE, &StoreOrLoadInst, AccessFn, Subscripts,
ArraySizes))
return false;

// Populate Sizes with scev expressions to be used in calculations later.
for (auto Idx : seq<unsigned>(1, Subscripts.size()))
Sizes.push_back(
SE.getConstant(Subscripts[Idx]->getType(), ArraySizes[Idx - 1]));
Sizes.push_back(ArraySizes[Idx - 1]);

LLVM_DEBUG({
dbgs() << "Delinearized subscripts of fixed-size array\n"
Expand Down
10 changes: 3 additions & 7 deletions polly/lib/Analysis/ScopBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ bool ScopBuilder::buildAccessMultiDimFixed(MemAccInst Inst, ScopStmt *Stmt) {
return false;

SmallVector<const SCEV *, 4> Subscripts;
SmallVector<int, 4> Sizes;
SmallVector<const SCEV *, 4> Sizes;
getIndexExpressionsFromGEP(SE, GEP, Subscripts, Sizes);
auto *BasePtr = GEP->getOperand(0);

Expand All @@ -1475,8 +1475,6 @@ bool ScopBuilder::buildAccessMultiDimFixed(MemAccInst Inst, ScopStmt *Stmt) {
if (BasePtr != BasePointer->getValue())
return false;

std::vector<const SCEV *> SizesSCEV;

Comment on lines -1478 to -1479
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the declaration needs to be moved.

const InvariantLoadsSetTy &ScopRIL = scop->getRequiredInvariantLoads();

Loop *SurroundingLoop = Stmt->getSurroundingLoop();
Expand All @@ -1494,11 +1492,9 @@ bool ScopBuilder::buildAccessMultiDimFixed(MemAccInst Inst, ScopStmt *Stmt) {
if (Sizes.empty())
return false;

std::vector<const SCEV *> SizesSCEV;
SizesSCEV.push_back(nullptr);

for (auto V : Sizes)
SizesSCEV.push_back(SE.getSCEV(
ConstantInt::get(IntegerType::getInt64Ty(BasePtr->getContext()), V)));
SizesSCEV.insert(SizesSCEV.end(), Sizes.begin(), Sizes.end());

addArrayAccess(Stmt, Inst, AccType, BasePointer->getValue(), ElementType,
true, Subscripts, SizesSCEV, Val);
Expand Down
Loading