[llvm-commits] [llvm] r63718 - in /llvm/trunk: lib/Analysis/AliasAnalysis.cpp lib/Analysis/BasicAliasAnalysis.cpp test/Analysis/BasicAA/cas.ll
Owen Anderson
resistor at mac.com
Tue Feb 3 21:16:47 PST 2009
Author: resistor
Date: Tue Feb 3 23:16:46 2009
New Revision: 63718
URL: http://llvm.org/viewvc/llvm-project?rev=63718&view=rev
Log:
Finish making AliasAnalysis aware of the fact that most atomic intrinsics only dereference their arguments, and enhance
BasicAA to make use of this fact when computing ModRef info.
Added:
llvm/trunk/test/Analysis/BasicAA/cas.ll
Modified:
llvm/trunk/lib/Analysis/AliasAnalysis.cpp
llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
Modified: llvm/trunk/lib/Analysis/AliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/AliasAnalysis.cpp?rev=63718&r1=63717&r2=63718&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/AliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/AliasAnalysis.cpp Tue Feb 3 23:16:46 2009
@@ -150,6 +150,27 @@
AliasAnalysis::ModRefBehavior
AliasAnalysis::getModRefBehavior(Function *F,
std::vector<PointerAccessInfo> *Info) {
+ if (F->isIntrinsic()) {
+ switch (F->getIntrinsicID()) {
+ case Intrinsic::atomic_cmp_swap:
+ case Intrinsic::atomic_load_add:
+ case Intrinsic::atomic_load_and:
+ case Intrinsic::atomic_load_max:
+ case Intrinsic::atomic_load_min:
+ case Intrinsic::atomic_load_nand:
+ case Intrinsic::atomic_load_or:
+ case Intrinsic::atomic_load_sub:
+ case Intrinsic::atomic_load_umax:
+ case Intrinsic::atomic_load_umin:
+ case Intrinsic::atomic_load_xor:
+ case Intrinsic::atomic_swap:
+ // CAS and related intrinsics only access their arguments.
+ return AliasAnalysis::AccessesArguments;
+ default:
+ break;
+ }
+ }
+
if (F->doesNotAccessMemory())
// Can't do better than this.
return DoesNotAccessMemory;
Modified: llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp?rev=63718&r1=63717&r2=63718&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp Tue Feb 3 23:16:46 2009
@@ -256,6 +256,22 @@
//
AliasAnalysis::ModRefResult
BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
+ // If the function only accesses its arguments, it suffices to check that
+ // P does not alias any of those arguments.
+ if (AliasAnalysis::getModRefBehavior(CS, 0) ==
+ AliasAnalysis::AccessesArguments) {
+ bool doesAlias = false;
+ for (CallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end();
+ AI != AE; ++AI)
+ if (alias(*AI, ~0U, P, Size) != NoAlias) {
+ doesAlias = true;
+ break;
+ }
+
+ if (!doesAlias)
+ return NoModRef;
+ }
+
if (!isa<Constant>(P)) {
const Value *Object = P->getUnderlyingObject();
Added: llvm/trunk/test/Analysis/BasicAA/cas.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BasicAA/cas.ll?rev=63718&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/BasicAA/cas.ll (added)
+++ llvm/trunk/test/Analysis/BasicAA/cas.ll Tue Feb 3 23:16:46 2009
@@ -0,0 +1,14 @@
+; RUN: llvm-as < %s | opt -basicaa -gvn | llvm-dis | grep load | count 1
+
+ at flag0 = internal global i32 zeroinitializer
+ at turn = internal global i32 zeroinitializer
+
+
+define i32 @main() {
+ %a = load i32* @flag0
+ %b = tail call i32 @llvm.atomic.swap.i32.p0i32(i32* @turn, i32 1)
+ %c = load i32* @flag0
+ ret i32 %c
+}
+
+declare i32 @llvm.atomic.swap.i32.p0i32(i32*, i32) nounwind
\ No newline at end of file
More information about the llvm-commits
mailing list