[llvm] r238762 - Teach the IR Sink pass to (conservatively) respect convergent annotations.
Owen Anderson
resistor at mac.com
Mon Jun 1 10:20:32 PDT 2015
Author: resistor
Date: Mon Jun 1 12:20:31 2015
New Revision: 238762
URL: http://llvm.org/viewvc/llvm-project?rev=238762&view=rev
Log:
Teach the IR Sink pass to (conservatively) respect convergent annotations.
Added:
llvm/trunk/test/Transforms/Sink/convergent.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/Sink.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/Sink.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Sink.cpp?rev=238762&r1=238761&r2=238762&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/Sink.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/Sink.cpp Mon Jun 1 12:20:31 2015
@@ -172,6 +172,12 @@ static bool isSafeToMove(Instruction *In
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;
}
Added: llvm/trunk/test/Transforms/Sink/convergent.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Sink/convergent.ll?rev=238762&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/Sink/convergent.ll (added)
+++ llvm/trunk/test/Transforms/Sink/convergent.ll Mon Jun 1 12:20:31 2015
@@ -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
+
More information about the llvm-commits
mailing list