Inconsistent results of dependence analysis


I am trying to use Dependence analysis to figure out some information form my benchmarks. However, I got different results by using LLVM analysis and my own pass. For example I have this case:

int test(int a, int* out, int N)
int sum = 0;
for(i = 2; i < N; ++i)
out[i] = a + i;
sum += out[i - 2];
return sum;

I compiled this C code by using the following command:

clang -fno-unroll-loops -emit-llvm -O2 -c -o test.bc test.c

Then I run DependenceAnalysis pass:

opt -basicaa -mem2reg -indvars -instcombine -instnamer -loop-simplify -mergereturn -da -analyze test.bc > /dev/null

and got this result:

Printing analysis ‘Dependence Analysis’ for function ‘test’:
da analyze - none!
da analyze - consistent flow [2]!
da analyze - none!

Actually this what I expect to got. However if I write a pass like this:


virtual void getAnalysisUsage(AnalysisUsage &AU) const


bool TestPass::runOnFunction(Function& F)
llvmDependenceAnalysis = &(getAnalysis(F));

// The following code is copied from DependenceAnalysis.cpp:dumpExampleDependence (157 - 182)
for (inst_iterator SrcI = inst_begin(F), SrcE = inst_end(F); SrcI != SrcE; ++SrcI) { … SKIP… }

return true;

And I executed this pass by using the following command:

opt -basicaa -mem2reg -indvars -instcombine -instnamer -loop-simplify -mergereturn -load ./ -test-pass test.bc > /dev/null

at this time I got:

da analyze - confused!
da analyze - confused!

da analyze - confused!

Am I doing a wrong usage about this analysis?


Not sure if this is the root cause, but one difference between the two lines is the “-analyse” on the first one. This will change behaviour between the two runs.