diff --git a/llvm/include/llvm/Analysis/Delinearization.h b/llvm/include/llvm/Analysis/Delinearization.h index b9fc0bcf4743..8fb30925b1ba 100644 --- a/llvm/include/llvm/Analysis/Delinearization.h +++ b/llvm/include/llvm/Analysis/Delinearization.h @@ -154,15 +154,15 @@ bool validateDelinearizationResult(ScalarEvolution &SE, /// /// 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 &Subscripts, - SmallVectorImpl &Sizes); + SmallVectorImpl &Sizes); struct DelinearizationPrinterPass : public PassInfoMixin { diff --git a/llvm/lib/Analysis/Delinearization.cpp b/llvm/lib/Analysis/Delinearization.cpp index 686622feec47..31dab99c91f2 100644 --- a/llvm/lib/Analysis/Delinearization.cpp +++ b/llvm/lib/Analysis/Delinearization.cpp @@ -824,12 +824,13 @@ bool llvm::validateDelinearizationResult(ScalarEvolution &SE, bool llvm::getIndexExpressionsFromGEP(ScalarEvolution &SE, const GetElementPtrInst *GEP, SmallVectorImpl &Subscripts, - SmallVectorImpl &Sizes) { + SmallVectorImpl &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"); LLVM_DEBUG(dbgs() << "\nGEP to delinearize: " << *GEP << "\n"); Type *Ty = nullptr; + Type *IndexTy = SE.getEffectiveSCEVType(GEP->getPointerOperandType()); bool DroppedFirstDim = false; for (unsigned i = 1; i < GEP->getNumOperands(); i++) { const SCEV *Expr = SE.getSCEV(GEP->getOperand(i)); @@ -855,7 +856,7 @@ bool llvm::getIndexExpressionsFromGEP(ScalarEvolution &SE, Subscripts.push_back(Expr); if (!(DroppedFirstDim && i == 2)) - Sizes.push_back(ArrayTy->getNumElements()); + Sizes.push_back(SE.getConstant(IndexTy, ArrayTy->getNumElements())); Ty = ArrayTy->getElementType(); } diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp index fe07b7edb671..b0cfaf6e5272 100644 --- a/llvm/lib/Analysis/DependenceAnalysis.cpp +++ b/llvm/lib/Analysis/DependenceAnalysis.cpp @@ -3265,7 +3265,7 @@ bool DependenceInfo::tryDelinearizeFixedSize( 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(); diff --git a/polly/lib/Analysis/ScopBuilder.cpp b/polly/lib/Analysis/ScopBuilder.cpp index 60a1e0091675..0f96c8923249 100644 --- a/polly/lib/Analysis/ScopBuilder.cpp +++ b/polly/lib/Analysis/ScopBuilder.cpp @@ -1464,7 +1464,7 @@ bool ScopBuilder::buildAccessMultiDimFixed(MemAccInst Inst, ScopStmt *Stmt) { return false; SmallVector Subscripts; - SmallVector Sizes; + SmallVector Sizes; getIndexExpressionsFromGEP(SE, GEP, Subscripts, Sizes); auto *BasePtr = GEP->getOperand(0); @@ -1476,8 +1476,6 @@ bool ScopBuilder::buildAccessMultiDimFixed(MemAccInst Inst, ScopStmt *Stmt) { if (BasePtr != BasePointer->getValue()) return false; - std::vector SizesSCEV; - const InvariantLoadsSetTy &ScopRIL = scop->getRequiredInvariantLoads(); Loop *SurroundingLoop = Stmt->getSurroundingLoop(); @@ -1495,11 +1493,9 @@ bool ScopBuilder::buildAccessMultiDimFixed(MemAccInst Inst, ScopStmt *Stmt) { if (Sizes.empty()) return false; + std::vector 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);