@@ -195,28 +195,44 @@ LoopDependenceAnalysis::analysePair(DependencePair *P) const {
195
195
196
196
// FIXME: Is filtering coupled subscripts necessary?
197
197
198
- // Analyse indices pairwise (FIXME: use GetGEPOperands from BasicAA), adding
198
+ // Collect GEP operand pairs (FIXME: use GetGEPOperands from BasicAA), adding
199
199
// 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)) {
205
208
const SCEV* aSCEV = (aIdx != aEnd) ? SE->getSCEV (*aIdx) : GetZeroSCEV (SE);
206
209
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) {
207
226
Subscript subscript;
208
- DependenceResult result = analyseSubscript (aSCEV, bSCEV , &subscript);
227
+ DependenceResult result = analyseSubscript (i-> first , i-> second , &subscript);
209
228
if (result != Dependent) {
210
229
// We either proved independence or failed to analyse this subscript.
211
230
// Further subscripts will not improve the situation, so abort early.
212
231
return result;
213
232
}
214
233
P->Subscripts .push_back (subscript);
215
- if (aIdx != aEnd) ++aIdx;
216
- if (bIdx != bEnd) ++bIdx;
217
234
}
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.
220
236
return Dependent;
221
237
}
222
238
0 commit comments