return V;
}
+/// isNoAliasCall - Return true if this pointer is returned by a noalias
+/// function.
+static bool isNoAliasCall(const Value *V) {
+ if (isa<CallInst>(V) || isa<InvokeInst>(V))
+ return CallSite(const_cast<Instruction*>(cast<Instruction>(V)))
+ .paramHasAttr(0, Attribute::NoAlias);
+ return false;
+}
+
/// isIdentifiedObject - Return true if this pointer refers to a distinct and
/// identifiable object. This returns true for:
/// Global Variables and Functions
/// Allocas and Mallocs
/// ByVal and NoAlias Arguments
+/// NoAlias returns
///
static bool isIdentifiedObject(const Value *V) {
- if (isa<GlobalValue>(V) || isa<AllocationInst>(V))
+ if (isa<GlobalValue>(V) || isa<AllocationInst>(V) || isNoAliasCall(V))
return true;
if (const Argument *A = dyn_cast<Argument>(V))
return A->hasNoAliasAttr() || A->hasByValAttr();
/// object that never escapes from the function.
static bool isNonEscapingLocalObject(const Value *V) {
// If this is a local allocation, check to see if it escapes.
- if (isa<AllocationInst>(V))
+ if (isa<AllocationInst>(V) || isNoAliasCall(V))
return !AddressMightEscape(V);
// If this is an argument that corresponds to a byval or noalias argument,
/// by V is smaller than Size.
static bool isObjectSmallerThan(const Value *V, unsigned Size,
const TargetData &TD) {
- const Type *AccessTy = 0;
- if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
+ const Type *AccessTy;
+ if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
AccessTy = GV->getType()->getElementType();
-
- if (const AllocationInst *AI = dyn_cast<AllocationInst>(V))
+ } else if (const AllocationInst *AI = dyn_cast<AllocationInst>(V)) {
if (!AI->isArrayAllocation())
AccessTy = AI->getType()->getElementType();
-
- if (const Argument *A = dyn_cast<Argument>(V))
+ else
+ return false;
+ } else if (const Argument *A = dyn_cast<Argument>(V)) {
if (A->hasByValAttr())
AccessTy = cast<PointerType>(A->getType())->getElementType();
+ else
+ return false;
+ } else {
+ return false;
+ }
- if (AccessTy && AccessTy->isSized())
+ if (AccessTy->isSized())
return TD.getABITypeSize(AccessTy) < Size;
return false;
}
// Are we checking for alias of the same value?
if (V1 == V2) return MustAlias;
- if ((!isa<PointerType>(V1->getType()) || !isa<PointerType>(V2->getType())) &&
- V1->getType() != Type::Int64Ty && V2->getType() != Type::Int64Ty)
+ if (!isa<PointerType>(V1->getType()) || !isa<PointerType>(V2->getType()))
return NoAlias; // Scalars cannot alias each other
// Strip off cast instructions...
if (isIdentifiedObject(O1) && isIdentifiedObject(O2))
return NoAlias;
- // Incoming argument cannot alias locally allocated object!
- if ((isa<Argument>(O1) && isa<AllocationInst>(O2)) ||
- (isa<Argument>(O2) && isa<AllocationInst>(O1)))
+ // Arguments can't alias with local allocations or noalias calls.
+ if ((isa<Argument>(O1) && (isa<AllocationInst>(O2) || isNoAliasCall(O2))) ||
+ (isa<Argument>(O2) && (isa<AllocationInst>(O1) || isNoAliasCall(O1))))
return NoAlias;
-
+
// Most objects can't alias null.
if ((isa<ConstantPointerNull>(V2) && isKnownNonNull(O1)) ||
(isa<ConstantPointerNull>(V1) && isKnownNonNull(O2)))
return MayAlias;
}
-// This function is used to determin if the indices of two GEP instructions are
+// This function is used to determine if the indices of two GEP instructions are
// equal. V1 and V2 are the indices.
static bool IndexOperandsEqual(Value *V1, Value *V2) {
if (V1->getType() == V2->getType())