Fix PR2792: treat volatile loads as writing memory somewhere.
authorDuncan Sands <baldrick@free.fr>
Sat, 13 Sep 2008 12:45:50 +0000 (12:45 +0000)
committerDuncan Sands <baldrick@free.fr>
Sat, 13 Sep 2008 12:45:50 +0000 (12:45 +0000)
Treat stores as reading memory, just to play safe.

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

lib/Analysis/IPA/GlobalsModRef.cpp
test/Analysis/GlobalsModRef/2008-09-13-VolatileRead.ll [new file with mode: 0644]

index 390a6028eb4df7c420c58fe3ff2004af7dffc7ce..74327d5c60b60b3b3d997b6ecc964316b35e52b8 100644 (file)
@@ -431,12 +431,20 @@ void GlobalsModRef::AnalyzeCallGraph(CallGraph &CG, Module &M) {
       for (inst_iterator II = inst_begin(SCC[i]->getFunction()),
              E = inst_end(SCC[i]->getFunction());
            II != E && FunctionEffect != ModRef; ++II)
-        if (isa<LoadInst>(*II))
+        if (isa<LoadInst>(*II)) {
           FunctionEffect |= Ref;
-        else if (isa<StoreInst>(*II))
+          if (cast<LoadInst>(*II).isVolatile())
+            // Volatile loads may have side-effects, so mark them as writing
+            // memory (for example, a flag inside the processor).
+            FunctionEffect |= Mod;
+        } else if (isa<StoreInst>(*II)) {
           FunctionEffect |= Mod;
-        else if (isa<MallocInst>(*II) || isa<FreeInst>(*II))
+          if (cast<StoreInst>(*II).isVolatile())
+            // Treat volatile stores as reading memory somewhere.
+            FunctionEffect |= Ref;
+        } else if (isa<MallocInst>(*II) || isa<FreeInst>(*II)) {
           FunctionEffect |= ModRef;
+        }
 
     if ((FunctionEffect & Mod) == 0)
       ++NumReadMemFunctions;
diff --git a/test/Analysis/GlobalsModRef/2008-09-13-VolatileRead.ll b/test/Analysis/GlobalsModRef/2008-09-13-VolatileRead.ll
new file mode 100644 (file)
index 0000000..8ac9637
--- /dev/null
@@ -0,0 +1,9 @@
+; RUN: llvm-as < %s | opt -globalsmodref-aa -markmodref | llvm-dis | not grep read
+; PR2792
+
+@g = global i32 0              ; <i32*> [#uses=1]
+
+define i32 @f() {
+       %t = volatile load i32* @g              ; <i32> [#uses=1]
+       ret i32 %t
+}