Teach the IR Sink pass to (conservatively) respect convergent annotations.
authorOwen Anderson <resistor@mac.com>
Mon, 1 Jun 2015 17:20:31 +0000 (17:20 +0000)
committerOwen Anderson <resistor@mac.com>
Mon, 1 Jun 2015 17:20:31 +0000 (17:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238762 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/Sink.cpp
test/Transforms/Sink/convergent.ll [new file with mode: 0644]

index b169d5612f002674b03565e8d336d4363439a5f9..ec3a0186641efbdaaad7b0790d9d541cb7f4a29f 100644 (file)
@@ -172,6 +172,12 @@ static bool isSafeToMove(Instruction *Inst, AliasAnalysis *AA,
   if (isa<TerminatorInst>(Inst) || isa<PHINode>(Inst))
     return false;
 
+  // Convergent operations can only be moved to control equivalent blocks.
+  if (auto CS = CallSite(Inst)) {
+    if (CS.hasFnAttr(Attribute::Convergent))
+      return false;
+  }
+
   return true;
 }
 
diff --git a/test/Transforms/Sink/convergent.ll b/test/Transforms/Sink/convergent.ll
new file mode 100644 (file)
index 0000000..49207db
--- /dev/null
@@ -0,0 +1,24 @@
+; RUN: opt -sink -S < %s | FileCheck %s
+
+; Verify that IR sinking does not move convergent operations to
+; blocks that are not control equivalent.
+
+; CHECK: define i32 @foo
+; CHECK: entry
+; CHECK-NEXT: call i32 @bar
+; CHECK-NEXT: br i1 %arg
+
+define i32 @foo(i1 %arg) {
+entry:
+  %c = call i32 @bar() readonly convergent
+  br i1 %arg, label %then, label %end
+
+then:
+  ret i32 %c
+
+end:
+  ret i32 0
+}
+
+declare i32 @bar() readonly convergent
+