Skip to content

Commit c08f49b

Browse files
authored
[delinearize] use SCEV exprs in getIndexExpressionsFromGEP (#162888)
clean up interface of getIndexExpressionsFromGEP to get SCEV expressions instead of int for Sizes of the arrays. This intends to simplify the code in #156342 by avoiding conversions from SCEV to int and back to SCEV.
1 parent c44b9ec commit c08f49b

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

llvm/include/llvm/Analysis/Delinearization.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ bool validateDelinearizationResult(ScalarEvolution &SE,
154154
///
155155
/// This function optimistically assumes the GEP references into a fixed size
156156
/// array. If this is actually true, this function returns a list of array
157-
/// subscript expressions in \p Subscripts and a list of integers describing
158-
/// the size of the individual array dimensions in \p Sizes. Both lists have
159-
/// either equal length or the size list is one element shorter in case there
160-
/// is no known size available for the outermost array dimension. Returns true
161-
/// if successful and false otherwise.
157+
/// subscript expressions in \p Subscripts and a list of SCEV expressions
158+
/// describing the size of the individual array dimensions in \p Sizes. Both
159+
/// lists have either equal length or the size list is one element shorter in
160+
/// case there is no known size available for the outermost array dimension.
161+
/// Returns true if successful and false otherwise.
162162
bool getIndexExpressionsFromGEP(ScalarEvolution &SE,
163163
const GetElementPtrInst *GEP,
164164
SmallVectorImpl<const SCEV *> &Subscripts,
165-
SmallVectorImpl<int> &Sizes);
165+
SmallVectorImpl<const SCEV *> &Sizes);
166166

167167
struct DelinearizationPrinterPass
168168
: public PassInfoMixin<DelinearizationPrinterPass> {

llvm/lib/Analysis/Delinearization.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,12 +824,13 @@ bool llvm::validateDelinearizationResult(ScalarEvolution &SE,
824824
bool llvm::getIndexExpressionsFromGEP(ScalarEvolution &SE,
825825
const GetElementPtrInst *GEP,
826826
SmallVectorImpl<const SCEV *> &Subscripts,
827-
SmallVectorImpl<int> &Sizes) {
827+
SmallVectorImpl<const SCEV *> &Sizes) {
828828
assert(Subscripts.empty() && Sizes.empty() &&
829829
"Expected output lists to be empty on entry to this function.");
830830
assert(GEP && "getIndexExpressionsFromGEP called with a null GEP");
831831
LLVM_DEBUG(dbgs() << "\nGEP to delinearize: " << *GEP << "\n");
832832
Type *Ty = nullptr;
833+
Type *IndexTy = SE.getEffectiveSCEVType(GEP->getPointerOperandType());
833834
bool DroppedFirstDim = false;
834835
for (unsigned i = 1; i < GEP->getNumOperands(); i++) {
835836
const SCEV *Expr = SE.getSCEV(GEP->getOperand(i));
@@ -855,7 +856,7 @@ bool llvm::getIndexExpressionsFromGEP(ScalarEvolution &SE,
855856

856857
Subscripts.push_back(Expr);
857858
if (!(DroppedFirstDim && i == 2))
858-
Sizes.push_back(ArrayTy->getNumElements());
859+
Sizes.push_back(SE.getConstant(IndexTy, ArrayTy->getNumElements()));
859860

860861
Ty = ArrayTy->getElementType();
861862
}

llvm/lib/Analysis/DependenceAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3265,7 +3265,7 @@ bool DependenceInfo::tryDelinearizeFixedSize(
32653265
return false;
32663266

32673267
// Check that the two size arrays are non-empty and equal in length and
3268-
// value.
3268+
// value. SCEV expressions are uniqued, so we can compare pointers.
32693269
if (SrcSizes.size() != DstSizes.size() ||
32703270
!std::equal(SrcSizes.begin(), SrcSizes.end(), DstSizes.begin())) {
32713271
SrcSubscripts.clear();

polly/lib/Analysis/ScopBuilder.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ bool ScopBuilder::buildAccessMultiDimFixed(MemAccInst Inst, ScopStmt *Stmt) {
14641464
return false;
14651465

14661466
SmallVector<const SCEV *, 4> Subscripts;
1467-
SmallVector<int, 4> Sizes;
1467+
SmallVector<const SCEV *, 4> Sizes;
14681468
getIndexExpressionsFromGEP(SE, GEP, Subscripts, Sizes);
14691469
auto *BasePtr = GEP->getOperand(0);
14701470

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

1479-
std::vector<const SCEV *> SizesSCEV;
1480-
14811479
const InvariantLoadsSetTy &ScopRIL = scop->getRequiredInvariantLoads();
14821480

14831481
Loop *SurroundingLoop = Stmt->getSurroundingLoop();
@@ -1495,11 +1493,9 @@ bool ScopBuilder::buildAccessMultiDimFixed(MemAccInst Inst, ScopStmt *Stmt) {
14951493
if (Sizes.empty())
14961494
return false;
14971495

1496+
std::vector<const SCEV *> SizesSCEV;
14981497
SizesSCEV.push_back(nullptr);
1499-
1500-
for (auto V : Sizes)
1501-
SizesSCEV.push_back(SE.getSCEV(
1502-
ConstantInt::get(IntegerType::getInt64Ty(BasePtr->getContext()), V)));
1498+
SizesSCEV.insert(SizesSCEV.end(), Sizes.begin(), Sizes.end());
15031499

15041500
addArrayAccess(Stmt, Inst, AccType, BasePointer->getValue(), ElementType,
15051501
true, Subscripts, SizesSCEV, Val);

0 commit comments

Comments
 (0)