[LLVMdev] Wrong AliasAnalysis::getModRefInfo result

Welson Sun welson.sun at gmail.com
Tue Feb 14 17:12:54 PST 2012


Just want to test out the LLVM's AliasAnalysis::getModRefInfo API. The
input C code is very simple:

void foo(int *a, int *b)
{
  for(int i=0; i<10; i++)
    b[i] = a[i]*a[i];
}

int main()
{
  int a[10];
  int b[10];

  for(int i=0; i<10; i++)
    a[i] = i;

  foo(a,b);

  return 0;
}

Obviously, for "foo", it only reads from array "a" and only writes to array
"b".

The LLVM pass:
    virtual bool runOnFunction(Function &F) {
      ++HelloCounter;
      errs() << "Hello: ";
      errs().write_escaped(F.getName()) << '\n';

      AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
      for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
        Instruction *Inst = &*I;
        if ( CallInst *ci = dyn_cast<CallInst>(Inst) ){
          ci->dump();
          for(int i = 0; i < ci->getNumArgOperands(); i++){
            Value *v = ci->getArgOperand(i);
            if (GetElementPtrInst *vi = dyn_cast<GetElementPtrInst>(v)){
              Value *vPtr = vi->getPointerOperand();
              vPtr->dump();
              if ( AllocaInst *allo = dyn_cast<AllocaInst>(vPtr) ) {
                const Type *t = allo->getAllocatedType();
                if ( const ArrayType *at = dyn_cast<ArrayType>(t) ) {
                  int64_t size = at->getNumElements() *
at->getElementType()->getPrimitiveSizeInBits() / 8;
                  ImmutableCallSite cs(ci);
                  AliasAnalysis::Location loc(v, size);
                  errs() << AA.getModRefInfo(ci, loc) << "\n";
                }
              }
            }
          }
        }
      }

      return false;
    }


However, the result is "3" for both a and b, which is both read and write.
What's the problem? I am not quite sure if I get the
AliasAnalysis::Location right, what is exactly "address-units" for the size
of the location? And did I get the starting address of the Location right?
I tried v, vi and vPtr, same result.


Any insight helps,
Welson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120214/fab3ba30/attachment.html>


More information about the llvm-dev mailing list