Skip to content

Commit d3a44b5

Browse files
committed
Restrict LDA to GEPs with the same pointer offset.
We can not simply apply ZIV testing to the pointer offsets, as this would incorrectly return independence for e.g. (GEP x,0,i; GEP x,1,-i). llvm-svn: 78155
1 parent 3e5b272 commit d3a44b5

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

llvm/lib/Analysis/LoopDependenceAnalysis.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,28 +195,44 @@ LoopDependenceAnalysis::analysePair(DependencePair *P) const {
195195

196196
// FIXME: Is filtering coupled subscripts necessary?
197197

198-
// Analyse indices pairwise (FIXME: use GetGEPOperands from BasicAA), adding
198+
// Collect GEP operand pairs (FIXME: use GetGEPOperands from BasicAA), adding
199199
// trailing zeroes to the smaller GEP, if needed.
200-
GEPOperator::const_op_iterator aIdx = aGEP->idx_begin(),
201-
aEnd = aGEP->idx_end(),
202-
bIdx = bGEP->idx_begin(),
203-
bEnd = bGEP->idx_end();
204-
while (aIdx != aEnd && bIdx != bEnd) {
200+
typedef SmallVector<std::pair<const SCEV*, const SCEV*>, 4> GEPOpdPairsTy;
201+
GEPOpdPairsTy opds;
202+
for(GEPOperator::const_op_iterator aIdx = aGEP->idx_begin(),
203+
aEnd = aGEP->idx_end(),
204+
bIdx = bGEP->idx_begin(),
205+
bEnd = bGEP->idx_end();
206+
aIdx != aEnd && bIdx != bEnd;
207+
aIdx += (aIdx != aEnd), bIdx += (bIdx != bEnd)) {
205208
const SCEV* aSCEV = (aIdx != aEnd) ? SE->getSCEV(*aIdx) : GetZeroSCEV(SE);
206209
const SCEV* bSCEV = (bIdx != bEnd) ? SE->getSCEV(*bIdx) : GetZeroSCEV(SE);
210+
opds.push_back(std::make_pair(aSCEV, bSCEV));
211+
}
212+
213+
if (!opds.empty() && opds[0].first != opds[0].second) {
214+
// We cannot (yet) handle arbitrary GEP pointer offsets. By limiting
215+
//
216+
// TODO: this could be relaxed by adding the size of the underlying object
217+
// to the first subscript. If we have e.g. (GEP x,0,i; GEP x,2,-i) and we
218+
// know that x is a [100 x i8]*, we could modify the first subscript to be
219+
// (i, 200-i) instead of (i, -i).
220+
return Unknown;
221+
}
222+
223+
// Now analyse the collected operand pairs (skipping the GEP ptr offsets).
224+
for (GEPOpdPairsTy::const_iterator i = opds.begin() + 1, end = opds.end();
225+
i != end; ++i) {
207226
Subscript subscript;
208-
DependenceResult result = analyseSubscript(aSCEV, bSCEV, &subscript);
227+
DependenceResult result = analyseSubscript(i->first, i->second, &subscript);
209228
if (result != Dependent) {
210229
// We either proved independence or failed to analyse this subscript.
211230
// Further subscripts will not improve the situation, so abort early.
212231
return result;
213232
}
214233
P->Subscripts.push_back(subscript);
215-
if (aIdx != aEnd) ++aIdx;
216-
if (bIdx != bEnd) ++bIdx;
217234
}
218-
// Either there were no subscripts or all subscripts were analysed to be
219-
// dependent; in both cases we know the accesses are dependent.
235+
// We successfully analysed all subscripts but failed to prove independence.
220236
return Dependent;
221237
}
222238

0 commit comments

Comments
 (0)