<p dir="ltr">Lgtm</p>
<br><div class="gmail_quote"><div dir="ltr">On Fri, Feb 12, 2016, 12:56 PM Justin Lebar <<a href="mailto:jlebar@google.com">jlebar@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">jlebar updated this revision to Diff 47837.<br>
jlebar marked an inline comment as done.<br>
jlebar added a comment.<br>
<br>
Simplify test.<br>
<br>
This is a lot better, thank you for the suggestion.<br>
<br>
<br>
<a href="http://reviews.llvm.org/D17128" rel="noreferrer" target="_blank">http://reviews.llvm.org/D17128</a><br>
<br>
Files:<br>
lib/Transforms/Utils/SimplifyCFG.cpp<br>
test/Transforms/SimplifyCFG/attr-convergent.ll<br>
<br>
Index: test/Transforms/SimplifyCFG/attr-convergent.ll<br>
===================================================================<br>
--- /dev/null<br>
+++ test/Transforms/SimplifyCFG/attr-convergent.ll<br>
@@ -0,0 +1,28 @@<br>
+; RUN: opt < %s -simplifycfg -S | FileCheck %s<br>
+<br>
+; Checks that the SimplifyCFG pass won't duplicate a call to a function marked<br>
+; convergent.<br>
+;<br>
+; CHECK: call void @barrier<br>
+; CHECK-NOT: call void @barrier<br>
+define void @check(i1 %cond, i32* %out) {<br>
+entry:<br>
+ br i1 %cond, label %if.then, label %if.end<br>
+<br>
+if.then:<br>
+ store i32 5, i32* %out<br>
+ br label %if.end<br>
+<br>
+if.end:<br>
+ %x = phi i1 [ true, %entry ], [ false, %if.then ]<br>
+ call void @barrier()<br>
+ br i1 %x, label %cond.end, label %cond.false<br>
+<br>
+cond.false:<br>
+ br label %cond.end<br>
+<br>
+cond.end:<br>
+ ret void<br>
+}<br>
+<br>
+declare void @barrier() convergent<br>
Index: lib/Transforms/Utils/SimplifyCFG.cpp<br>
===================================================================<br>
--- lib/Transforms/Utils/SimplifyCFG.cpp<br>
+++ lib/Transforms/Utils/SimplifyCFG.cpp<br>
@@ -1690,19 +1690,6 @@<br>
return true;<br>
}<br>
<br>
-/// \returns True if this block contains a CallInst with the NoDuplicate<br>
-/// attribute.<br>
-static bool HasNoDuplicateCall(const BasicBlock *BB) {<br>
- for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) {<br>
- const CallInst *CI = dyn_cast<CallInst>(I);<br>
- if (!CI)<br>
- continue;<br>
- if (CI->cannotDuplicate())<br>
- return true;<br>
- }<br>
- return false;<br>
-}<br>
-<br>
/// Return true if we can thread a branch across this block.<br>
static bool BlockIsSimpleEnoughToThreadThrough(BasicBlock *BB) {<br>
BranchInst *BI = cast<BranchInst>(BB->getTerminator());<br>
@@ -1747,7 +1734,12 @@<br>
// Now we know that this block has multiple preds and two succs.<br>
if (!BlockIsSimpleEnoughToThreadThrough(BB)) return false;<br>
<br>
- if (HasNoDuplicateCall(BB)) return false;<br>
+ // Can't fold blocks that contain noduplicate or convergent calls.<br>
+ if (llvm::any_of(*BB, [](const Instruction &I) {<br>
+ const CallInst *CI = dyn_cast<CallInst>(&I);<br>
+ return CI && (CI->cannotDuplicate() || CI->isConvergent());<br>
+ }))<br>
+ return false;<br>
<br>
// Okay, this is a simple enough basic block. See if any phi values are<br>
// constants.<br>
<br>
<br>
</blockquote></div>