[llvm-commits] [llvm] r47247 - /llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp

Chris Lattner clattner at apple.com
Sun Feb 17 18:16:54 PST 2008


On Feb 17, 2008, at 1:29 PM, Owen Anderson wrote:

> Author: resistor
> Date: Sun Feb 17 15:29:08 2008
> New Revision: 47247
>
> URL: http://llvm.org/viewvc/llvm-project?rev=47247&view=rev
> Log:
> Teach getModRefInfo that memcpy, memmove, and memset don't "capture"  
> memory addresses.
> Also, noalias arguments are be considered "like" stack allocated  
> ones for this purpose, because
> the only way they can be modref'ed is if they escape somewhere in  
> the current function.

Very nice owen.

> +    case Instruction::Call:
> +      // If the call is to a few known safe intrinsics, we know  
> that it does
> +      // not escape
> +      if (isa<MemIntrinsic>(I))
> +        return false;
> +      else
> +        return true;

I fixed one minor problem with this: if you have a memintrinsic, you  
have to check other uses.

> @@ -247,8 +254,11 @@
>     // Allocations and byval arguments are "new" objects.
>     if (Object &&
>         (isa<AllocationInst>(Object) ||
> -         (isa<Argument>(Object) && cast<Argument>(Object)- 
> >hasByValAttr()))) {
> -      // Okay, the pointer is to a stack allocated object.  If we  
> can prove that
> +         (isa<Argument>(Object) &&
> +                                 (cast<Argument>(Object)- 
> >hasByValAttr() ||
> +                                  cast<Argument>(Object)- 
> >hasNoAliasAttr())))) {
> +      // Okay, the pointer is to a stack allocated (or effectively  
> so, for
> +      // for noalias parameters) object.  If we can prove that
>       // the pointer never "escapes", then we know the call cannot  
> clobber it,
>       // because it simply can't get its address.
>       if (!AddressMightEscape(Object))

Two problems with this code:

1. This will return nomodref for a memcpy that reads or writes a "non  
escaping" alloca.  I think that if AddressMightEscape returns false,  
you should loop over operands of the call, and see if  
getUnderlyingObject returns "Object" for any of the pointer arguments  
to the call.  If so, the call really could mod/ref the memory.

2. This code:

       // If this is a tail call and P points to a stack location, we  
know that
       // the tail call cannot access or modify the local stack.
       if (CallInst *CI = dyn_cast<CallInst>(CS.getInstruction()))
         if (CI->isTailCall() && !isa<MallocInst>(Object))
           return NoModRef;

is not safe for noalias arguments, only byval and allocas.

-Chris



More information about the llvm-commits mailing list