1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

Make BasicAliasAnalysis recognize the fact a noalias argument cannot alias another argument, even if the other argument is not itself marked noalias.

llvm-svn: 182755
This commit is contained in:
Michael Kuperstein 2013-05-28 08:17:48 +00:00
parent 0838ba10ee
commit ad5bd9ce5a
4 changed files with 51 additions and 4 deletions

View File

@ -584,6 +584,10 @@ struct DenseMapInfo<AliasAnalysis::Location> {
/// function.
bool isNoAliasCall(const Value *V);
/// isNoAliasArgument - Return true if this is an argument with the noalias
/// attribute.
bool isNoAliasArgument(const Value *V);
/// isIdentifiedObject - Return true if this pointer refers to a distinct and
/// identifiable object. This returns true for:
/// Global Variables and Functions (but not Global Aliases)

View File

@ -537,6 +537,15 @@ bool llvm::isNoAliasCall(const Value *V) {
return false;
}
/// isNoAliasArgument - Return true if this is an argument with the noalias
/// attribute.
bool llvm::isNoAliasArgument(const Value *V)
{
if (const Argument *A = dyn_cast<Argument>(V))
return A->hasNoAliasAttr();
return false;
}
/// isIdentifiedObject - Return true if this pointer refers to a distinct and
/// identifiable object. This returns true for:
/// Global Variables and Functions (but not Global Aliases)

View File

@ -142,6 +142,17 @@ static bool isObjectSize(const Value *V, uint64_t Size,
return ObjectSize != AliasAnalysis::UnknownSize && ObjectSize == Size;
}
/// isIdentifiedFunctionLocal - Return true if V is umabigously identified
/// at the function-level. Different IdentifiedFunctionLocals can't alias.
/// Further, an IdentifiedFunctionLocal can not alias with any function
/// arguments other than itself, which is not neccessarily true for
/// IdentifiedObjects.
static bool isIdentifiedFunctionLocal(const Value *V)
{
return isa<AllocaInst>(V) || isNoAliasCall(V) || isNoAliasArgument(V);
}
//===----------------------------------------------------------------------===//
// GetElementPtr Instruction Decomposition and Analysis
//===----------------------------------------------------------------------===//
@ -1205,10 +1216,10 @@ BasicAliasAnalysis::aliasCheck(const Value *V1, uint64_t V1Size,
(isa<Constant>(O2) && isIdentifiedObject(O1) && !isa<Constant>(O1)))
return NoAlias;
// Arguments can't alias with local allocations or noalias calls
// in the same function.
if (((isa<Argument>(O1) && (isa<AllocaInst>(O2) || isNoAliasCall(O2))) ||
(isa<Argument>(O2) && (isa<AllocaInst>(O1) || isNoAliasCall(O1)))))
// Function arguments can't alias with things that are known to be
// unambigously identified at the function level.
if ((isa<Argument>(O1) && isIdentifiedFunctionLocal(O2)) ||
(isa<Argument>(O2) && isIdentifiedFunctionLocal(O1)))
return NoAlias;
// Most objects can't alias null.

View File

@ -0,0 +1,23 @@
; RUN: opt < %s -basicaa -aa-eval -print-all-alias-modref-info 2>&1 | FileCheck %s
declare i32* @captures(i32* %cap) nounwind readonly
define void @no(i32* noalias %a, i32* %b) nounwind {
entry:
store i32 1, i32* %a
%cap = call i32* @captures(i32* %a) nounwind readonly
%l = load i32* %b
ret void
}
; CHECK: NoAlias: i32* %a, i32* %b
define void @yes(i32* %c, i32* %d) nounwind {
entry:
store i32 1, i32* %c
%cap = call i32* @captures(i32* %c) nounwind readonly
%l = load i32* %d
ret void
}
; CHECK: MayAlias: i32* %c, i32* %d