[llvm-commits] [llvm] r118417 - in /llvm/trunk: lib/Transforms/IPO/FunctionAttrs.cpp test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll
Dan Gohman
gohman at apple.com
Mon Nov 8 09:12:04 PST 2010
Author: djg
Date: Mon Nov 8 11:12:04 2010
New Revision: 118417
URL: http://llvm.org/viewvc/llvm-project?rev=118417&view=rev
Log:
Make FunctionAttrs TBAA-aware.
Added:
llvm/trunk/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll
Modified:
llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp
Modified: llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp?rev=118417&r1=118416&r2=118417&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp Mon Nov 8 11:12:04 2010
@@ -23,6 +23,7 @@
#include "llvm/CallGraphSCCPass.h"
#include "llvm/GlobalVariable.h"
#include "llvm/IntrinsicInst.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Analysis/CaptureTracking.h"
@@ -140,10 +141,14 @@
for (CallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end();
CI != CE; ++CI) {
Value *Arg = *CI;
- if (Arg->getType()->isPointerTy() &&
- !AA->pointsToConstantMemory(Arg, /*OrLocal=*/true))
- // Writes memory. Just give up.
- return false;
+ if (Arg->getType()->isPointerTy()) {
+ AliasAnalysis::Location Loc(Arg,
+ AliasAnalysis::UnknownSize,
+ I->getMetadata(LLVMContext::MD_tbaa));
+ if (!AA->pointsToConstantMemory(Arg, /*OrLocal=*/true))
+ // Writes memory. Just give up.
+ return false;
+ }
}
// Only reads and writes local memory.
continue;
@@ -153,16 +158,23 @@
}
} else if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
// Ignore non-volatile loads from local memory.
- if (!LI->isVolatile() &&
- AA->pointsToConstantMemory(LI->getPointerOperand(),
- /*OrLocal=*/true))
- continue;
+ if (!LI->isVolatile()) {
+ AliasAnalysis::Location Loc(LI->getPointerOperand(),
+ AA->getTypeStoreSize(LI->getType()),
+ LI->getMetadata(LLVMContext::MD_tbaa));
+ if (AA->pointsToConstantMemory(Loc, /*OrLocal=*/true))
+ continue;
+ }
} else if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
// Ignore non-volatile stores to local memory.
- if (!SI->isVolatile() &&
- AA->pointsToConstantMemory(SI->getPointerOperand(),
- /*OrLocal=*/true))
- continue;
+ if (!SI->isVolatile()) {
+ const Type *StoredType = SI->getValueOperand()->getType();
+ AliasAnalysis::Location Loc(SI->getPointerOperand(),
+ AA->getTypeStoreSize(StoredType),
+ SI->getMetadata(LLVMContext::MD_tbaa));
+ if (AA->pointsToConstantMemory(Loc, /*OrLocal=*/true))
+ continue;
+ }
}
// Any remaining instructions need to be taken seriously! Check if they
Added: llvm/trunk/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll?rev=118417&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll (added)
+++ llvm/trunk/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll Mon Nov 8 11:12:04 2010
@@ -0,0 +1,37 @@
+; RUN: opt < %s -enable-tbaa -tbaa -basicaa -functionattrs -S | FileCheck %s
+
+; FunctionAttrs should make use of TBAA.
+
+; CHECK: define void @test0_yes(i32* nocapture %p) nounwind readnone {
+define void @test0_yes(i32* %p) nounwind {
+ store i32 0, i32* %p, !tbaa !1
+ ret void
+}
+
+; CHECK: define void @test0_no(i32* nocapture %p) nounwind {
+define void @test0_no(i32* %p) nounwind {
+ store i32 0, i32* %p, !tbaa !2
+ ret void
+}
+
+; CHECK: define void @test1_yes(i32* %p) nounwind readonly {
+define void @test1_yes(i32* %p) nounwind {
+ call void @callee(i32* %p), !tbaa !1
+ ret void
+}
+
+; CHECK: define void @test1_no(i32* %p) nounwind {
+define void @test1_no(i32* %p) nounwind {
+ call void @callee(i32* %p), !tbaa !2
+ ret void
+}
+
+declare void @callee(i32* %p) nounwind
+
+; Root note.
+!0 = metadata !{ }
+
+; Invariant memory.
+!1 = metadata !{ metadata !"foo", metadata !0, i1 1 }
+; Not invariant memory.
+!2 = metadata !{ metadata !"foo", metadata !0, i1 0 }
More information about the llvm-commits
mailing list