[llvm-commits] [llvm] r138965 - in /llvm/trunk: lib/Transforms/Scalar/Sink.cpp test/Transforms/Sink/basic.ll

Eli Friedman eli.friedman at gmail.com
Thu Sep 1 14:21:24 PDT 2011


Author: efriedma
Date: Thu Sep  1 16:21:24 2011
New Revision: 138965

URL: http://llvm.org/viewvc/llvm-project?rev=138965&view=rev
Log:
Fix an issue with the IR sink pass found by inspection.  (I'm not sure anyone is actually using this, but might as well fix it since I found the issue.)


Modified:
    llvm/trunk/lib/Transforms/Scalar/Sink.cpp
    llvm/trunk/test/Transforms/Sink/basic.ll

Modified: llvm/trunk/lib/Transforms/Scalar/Sink.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Sink.cpp?rev=138965&r1=138964&r2=138965&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/Sink.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/Sink.cpp Thu Sep  1 16:21:24 2011
@@ -153,9 +153,13 @@
 
 static bool isSafeToMove(Instruction *Inst, AliasAnalysis *AA,
                          SmallPtrSet<Instruction *, 8> &Stores) {
-  if (LoadInst *L = dyn_cast<LoadInst>(Inst)) {
-    if (L->isVolatile()) return false;
 
+  if (Inst->mayWriteToMemory()) {
+    Stores.insert(Inst);
+    return false;
+  }
+
+  if (LoadInst *L = dyn_cast<LoadInst>(Inst)) {
     AliasAnalysis::Location Loc = AA->getLocation(L);
     for (SmallPtrSet<Instruction *, 8>::iterator I = Stores.begin(),
          E = Stores.end(); I != E; ++I)
@@ -163,11 +167,6 @@
         return false;
   }
 
-  if (Inst->mayWriteToMemory()) {
-    Stores.insert(Inst);
-    return false;
-  }
-
   if (isa<TerminatorInst>(Inst) || isa<PHINode>(Inst))
     return false;
 

Modified: llvm/trunk/test/Transforms/Sink/basic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Sink/basic.ll?rev=138965&r1=138964&r2=138965&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/Sink/basic.ll (original)
+++ llvm/trunk/test/Transforms/Sink/basic.ll Thu Sep  1 16:21:24 2011
@@ -20,3 +20,19 @@
 false:
   ret i32 0
 }
+
+; But don't sink volatile loads...
+
+;      CHECK: @foo2
+;      CHECK: volatile load
+; CHECK-NEXT: store i32
+
+define i32 @foo2(i1 %z) {
+  %l = volatile load i32* @A
+  store i32 0, i32* @B
+  br i1 %z, label %true, label %false
+true:
+  ret i32 %l
+false:
+  ret i32 0
+}





More information about the llvm-commits mailing list