================
@@ -3543,13 +3543,67 @@ static ConstantInt *getKnownValueOnEdge(Value *V, 
BasicBlock *From,
   return nullptr;
 }
 
+static bool isUncontrolledConvergentCall(CallBase *CB) {
+  return CB->isConvergent() && !isa<ConvergenceControlInst>(CB) &&
+         !CB->getConvergenceControlToken();
+}
+
+static bool reachesUncontrolledConvergentCallBeforeBlock(BasicBlock *From,
+                                                         BasicBlock *StopBB) {
+  // Walk predecessors of StopBB to find blocks that can reach it. Only
+  // convergent calls on a cycle with StopBB matter - a convergent call on a
+  // path to function exit cannot have its dynamic instance changed by
+  // threading.
+  SmallPtrSet<BasicBlock *, 8> CanReachStop;
+  SmallVector<BasicBlock *, 8> Worklist;
+  for (BasicBlock *Pred : predecessors(StopBB))
+    Worklist.push_back(Pred);
+
+  while (!Worklist.empty()) {
+    BasicBlock *BB = Worklist.pop_back_val();
+    if (BB == StopBB)
+      continue;
+    if (!CanReachStop.insert(BB).second)
+      continue;
+    if (CanReachStop.size() > MaxJumpThreadingLiveBlocks)
+      return true;
+    append_range(Worklist, predecessors(BB));
+  }
+
+  if (!CanReachStop.contains(From))
+    return false;
+
+  SmallPtrSet<BasicBlock *, 8> Visited;
+  Worklist.push_back(From);
+
+  while (!Worklist.empty()) {
+    BasicBlock *BB = Worklist.pop_back_val();
+    if (BB == StopBB || !CanReachStop.contains(BB))
+      continue;
+
+    if (!Visited.insert(BB).second)
+      continue;
+    if (Visited.size() > MaxJumpThreadingLiveBlocks)
----------------
shiltian wrote:

> I'm not sure I like overloading MaxJumpThreadingLiveBlocks here.

Yeah, fair. Do you want me to add a new option here, though I'm not sure how 
much it will help? Alternatively, I can just hard-code a number there.

>  Also, the amount of work we do here is also proportional to the size of the 
> basic blocks.

Right, but I don't see how to further improve this. Basically we want to check 
if there is any convergent calls inside a BB.

https://github.com/llvm/llvm-project/pull/204958
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to