If a function does a volatile load from a global constant, do not

consider it to be readonly.  In fact, don't even consider it to be
readonly if it does a volatile load from an AllocaInst either (it
is debatable as to whether readonly would be correct or not in this
case; play safe for the moment).  This fixes PR8279.

llvm-svn: 117783
This commit is contained in:
Duncan Sands 2010-10-30 12:59:44 +00:00
parent a71c9e2ebf
commit b8f3b14dfb
2 changed files with 14 additions and 4 deletions

View File

@ -188,12 +188,12 @@ bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) {
continue;
}
} else if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
// Ignore loads from local memory.
if (PointsToLocalMemory(LI->getPointerOperand()))
// Ignore non-volatile loads from local memory.
if (!LI->isVolatile() && PointsToLocalMemory(LI->getPointerOperand()))
continue;
} else if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
// Ignore stores to local memory.
if (PointsToLocalMemory(SI->getPointerOperand()))
// Ignore non-volatile stores to local memory.
if (!SI->isVolatile() && PointsToLocalMemory(SI->getPointerOperand()))
continue;
}

View File

@ -0,0 +1,10 @@
; RUN: opt < %s -functionattrs -S | FileCheck %s
; PR8279
@g = constant i32 1
define void @foo() {
; CHECK: void @foo() {
%tmp = volatile load i32* @g
ret void
}