OSDN Git Service

If a function does a volatile load from a global constant, do not
authorDuncan Sands <baldrick@free.fr>
Sat, 30 Oct 2010 12:59:44 +0000 (12:59 +0000)
committerDuncan Sands <baldrick@free.fr>
Sat, 30 Oct 2010 12:59:44 +0000 (12:59 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117783 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/FunctionAttrs.cpp
test/Transforms/FunctionAttrs/2010-10-30-volatile.ll [new file with mode: 0644]

index d4bce9e..39f4814 100644 (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;
       }
 
diff --git a/test/Transforms/FunctionAttrs/2010-10-30-volatile.ll b/test/Transforms/FunctionAttrs/2010-10-30-volatile.ll
new file mode 100644 (file)
index 0000000..f21fabc
--- /dev/null
@@ -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
+}