Fix an issue with the IR sink pass found by inspection. (I'm not sure anyone is...
authorEli Friedman <eli.friedman@gmail.com>
Thu, 1 Sep 2011 21:21:24 +0000 (21:21 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 1 Sep 2011 21:21:24 +0000 (21:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138965 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/Sink.cpp
test/Transforms/Sink/basic.ll

index 705f44204900ff67225def19318e5bd6d689b0d5..c83f56c4d2d7778b1712d541cf7038cf5ae48ca1 100644 (file)
@@ -153,9 +153,13 @@ bool Sinking::ProcessBlock(BasicBlock &BB) {
 
 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 @@ static bool isSafeToMove(Instruction *Inst, AliasAnalysis *AA,
         return false;
   }
 
-  if (Inst->mayWriteToMemory()) {
-    Stores.insert(Inst);
-    return false;
-  }
-
   if (isa<TerminatorInst>(Inst) || isa<PHINode>(Inst))
     return false;
 
index 54b7f1369de47a1f1e723b6ae62ac8f7f591c65a..81782e9d42c860d9edfa6adc4307855cd4a23db3 100644 (file)
@@ -20,3 +20,19 @@ true:
 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
+}