[llvm-commits] [llvm] r84079 - in /llvm/trunk: lib/Analysis/BasicAliasAnalysis.cpp test/Analysis/BasicAA/2009-10-13-GEP-BaseNoAlias.ll

Török Edwin edwintorok at gmail.com
Wed Oct 14 06:52:45 PDT 2009


On 2009-10-14 09:41, Evan Cheng wrote:
> Author: evancheng
> Date: Wed Oct 14 01:41:49 2009
> New Revision: 84079
>
> URL: http://llvm.org/viewvc/llvm-project?rev=84079&view=rev
> Log:
> Another BasicAA fix. If a value does not alias a GEP's base pointer, then it
> cannot alias the GEP. GEP pointer alias rule states this clearly:
> A pointer value formed from a getelementptr instruction is associated with the
> addresses associated with the first operand of the getelementptr.
>   
> Added:
>     llvm/trunk/test/Analysis/BasicAA/2009-10-13-GEP-BaseNoAlias.ll
> Modified:
>     llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
>
> Modified: llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp?rev=84079&r1=84078&r2=84079&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp (original)
> +++ llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp Wed Oct 14 01:41:49 2009
> @@ -428,49 +428,54 @@
>    SmallVector<Value*, 16> GEPOperands;
>    const Value *BasePtr = GetGEPOperands(V1, GEPOperands);
>  
> -  AliasResult R = aliasCheck(BasePtr, V1Size, V2, V2Size);
> -  if (R == MustAlias) {
> -    // If there is at least one non-zero constant index, we know they cannot
> -    // alias.
> -    bool ConstantFound = false;
> -    bool AllZerosFound = true;
> -    for (unsigned i = 0, e = GEPOperands.size(); i != e; ++i)
> -      if (const Constant *C = dyn_cast<Constant>(GEPOperands[i])) {
> -        if (!C->isNullValue()) {
> -          ConstantFound = true;
> -          AllZerosFound = false;
> -          break;
> -        }
> -      } else {
> +  AliasResult R = aliasCheck(BasePtr, ~0U, V2, V2Size);
> +  if (R != MustAlias)
> +    // If V2 may alias GEP base pointer, conservatively returns MayAlias.
>   

Hi Evan,

This gives MayAlias for a[4] and a[5], right? I think you shouldn't exit
for a MayAlias return, only for a NoAlias result:
you should check whether the [index1, index1+size1), and [index2,
index2+size2)  ranges overlap, which you seem to be doing later.


> +    // If V2 is known not to alias GEP base pointer, then the two values
> +    // cannot alias per GEP semantics: "A pointer value formed from a
> +    // getelementptr instruction is associated with the addresses associated
> +    // with the first operand of the getelementptr".
> +    return R;
> +
> +  // If there is at least one non-zero constant index, we know they cannot
> +  // alias.
> +  bool ConstantFound = false;
> +  bool AllZerosFound = true;
> +  for (unsigned i = 0, e = GEPOperands.size(); i != e; ++i)
> +    if (const Constant *C = dyn_cast<Constant>(GEPOperands[i])) {
> +      if (!C->isNullValue()) {
> +        ConstantFound = true;
>          AllZerosFound = false;
> +        break;
>        }
> +    } else {
> +      AllZerosFound = false;
> +    }
>  
> -    // If we have getelementptr <ptr>, 0, 0, 0, 0, ... and V2 must aliases
> -    // the ptr, the end result is a must alias also.
> -    if (AllZerosFound)
> -      return MustAlias;
> +  // If we have getelementptr <ptr>, 0, 0, 0, 0, ... and V2 must aliases
> +  // the ptr, the end result is a must alias also.
> +  if (AllZerosFound)
> +    return MustAlias;
>  
> -    if (ConstantFound) {
> -      if (V2Size <= 1 && V1Size <= 1)  // Just pointer check?
> -        return NoAlias;
> +  if (ConstantFound) {
> +    if (V2Size <= 1 && V1Size <= 1)  // Just pointer check?
> +      return NoAlias;
>  
> -      // Otherwise we have to check to see that the distance is more than
> -      // the size of the argument... build an index vector that is equal to
> -      // the arguments provided, except substitute 0's for any variable
> -      // indexes we find...
> -      if (TD &&
> -          cast<PointerType>(BasePtr->getType())->getElementType()->isSized()) {
> -        for (unsigned i = 0; i != GEPOperands.size(); ++i)
> -          if (!isa<ConstantInt>(GEPOperands[i]))
> -            GEPOperands[i] = Constant::getNullValue(GEPOperands[i]->getType());
> -        int64_t Offset =
> -          TD->getIndexedOffset(BasePtr->getType(),
> -                               &GEPOperands[0],
> -                               GEPOperands.size());
> +    // Otherwise we have to check to see that the distance is more than
> +    // the size of the argument... build an index vector that is equal to
> +    // the arguments provided, except substitute 0's for any variable
> +    // indexes we find...
>   

However I don't see how this code is reached if the AA returns MayAlias
for a[4] and a[5], as the manual states:
The MayAlias response is used whenever the two pointers might refer to
the same object. If the two memory objects overlap, but do not start at
the same location, return MayAlias.

Best regards,
--Edwin



More information about the llvm-commits mailing list