Iteration distance failed in DependenceAnalysis C++ API

Hi LLVM-ers,

(1) I tried to use the following command line to get the iteration distance of a loop-carried dependence of a simple program :

command line: opt -basicaa -da -analyze dis_test.ll

program: for ( int i=0; j < n; ++i ) {
b[i] = b[i-2] + 3;
}
results: da analyze — none!
da analyze — consistent anti [-2] (This is what I expected!!)
da analyze — none!

(2) However, when I tried to use the C++ API to do the same thing, the distance result is null.

My pass:

class IterationDistance : public DependenceAnalysis {

void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired(); AU.addRequired();
AU.addRequired();
AU.addRequired();
}

DependenceAnalysis *DA = &(getAnalysis());
auto D = DA->depends(Src, Des, true);

if (D->isAnti()) {
unsigned Levels = D->getLevels();
errs() << "levels = " << Levels << “\n”;
char Direction;
for (unsigned II = 1; II <= Levels; ++II) {

const SCEV *Distance = D->getDistance(II);
const SCEVConstant *SCEVConst = dyn_cast_or_null(Distance);

}

Results: levels = 0;
Distance is null.

(3) My guess is that the "levels = 0” which makes the Distance cannot be got. Can anyone help me with this?

Thanks!
Shvo