diff options
| author | Owen Anderson <resistor@mac.com> | 2015-06-01 17:20:31 +0000 |
|---|---|---|
| committer | Owen Anderson <resistor@mac.com> | 2015-06-01 17:20:31 +0000 |
| commit | 15d180550448a7561e5d3c7e1ffa22602f2b3ed7 (patch) | |
| tree | ddd1ad199183f01c9b9dffe3e3898d9d7a408292 | |
| parent | bfca0d7f7b1711e860c132491ed52b4efcb29aaa (diff) | |
| download | bcm5719-llvm-15d180550448a7561e5d3c7e1ffa22602f2b3ed7.tar.gz bcm5719-llvm-15d180550448a7561e5d3c7e1ffa22602f2b3ed7.zip | |
Teach the IR Sink pass to (conservatively) respect convergent annotations.
llvm-svn: 238762
| -rw-r--r-- | llvm/lib/Transforms/Scalar/Sink.cpp | 6 | ||||
| -rw-r--r-- | llvm/test/Transforms/Sink/convergent.ll | 24 |
2 files changed, 30 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/Sink.cpp b/llvm/lib/Transforms/Scalar/Sink.cpp index b169d5612f0..ec3a0186641 100644 --- a/llvm/lib/Transforms/Scalar/Sink.cpp +++ b/llvm/lib/Transforms/Scalar/Sink.cpp @@ -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/llvm/test/Transforms/Sink/convergent.ll b/llvm/test/Transforms/Sink/convergent.ll new file mode 100644 index 00000000000..49207dbc992 --- /dev/null +++ b/llvm/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 + |

