From 57e487e92c68437792c2d6f7e69f1d08164992ce Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Mon, 1 Jun 2015 17:20:31 +0000 Subject: [PATCH] Teach the IR Sink pass to (conservatively) respect convergent annotations. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238762 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/Sink.cpp | 6 ++++++ test/Transforms/Sink/convergent.ll | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 test/Transforms/Sink/convergent.ll diff --git a/lib/Transforms/Scalar/Sink.cpp b/lib/Transforms/Scalar/Sink.cpp index b169d5612f0..ec3a0186641 100644 --- a/lib/Transforms/Scalar/Sink.cpp +++ b/lib/Transforms/Scalar/Sink.cpp @@ -172,6 +172,12 @@ static bool isSafeToMove(Instruction *Inst, AliasAnalysis *AA, if (isa(Inst) || isa(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 index 00000000000..49207dbc992 --- /dev/null +++ b/test/Transforms/Sink/convergent.ll @@ -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 + -- 2.34.1