[PATCH] D88438: BreakCriticalEdges: bail if loop-simplify form requested for CallBr terminated BB

Bill Wendling via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 19:18:44 PDT 2020


void added a comment.

In D88438#2305068 <https://reviews.llvm.org/D88438#2305068>, @efriedma wrote:

>> The concept of splitting a critical edge is still relatively new to me; any thoughts on *why* it would not be ok to split a critical branch of an indirect-like jump?
>
> The problem has to do with blockaddress.
>
> For normal branches, splitting an edge is usually straightforward: you just introduce a new block that branches to the original block, and then you rewrite the branch in the predecessor.  But suppose you have a block with two indirectbr predecessors, and you want to split the edge.  In that case, the "rewrite the branch" step doesn't work: you can't rewrite the address argument to the indirectbr.  (Or at least, you can't without performing some invasive rewrite like indirectbr->switch lowering.)

Correkt. We had a long discussion during the original implementation. I eventually relented, because I couldn't figure out a way to implement it without making the code unbearably horrible.

The best way to think about critical edges is to imagine trying to resolve a PHI node in block BB. The PHI node is a pseudo instruction, which has to become a concrete instruction during code gen. Let's take a simple case where the value is an immediate: 42 on branch A (from predecessor P1 <https://reviews.llvm.org/P1>) and 37 on branch B (from predecessor P2 <https://reviews.llvm.org/P2>), and further that the result of the PHI node is some register rN. When resolving the PHI node, you'll push rN <- 42 to the bottom of P1 <https://reviews.llvm.org/P1> and rN <- 37 to the bottom of P2 <https://reviews.llvm.org/P2>. Nice!

Now if you have critical edges, things get messy. You can no longer push rN <- 42 and rN <- 37 into the predecessor blocks, because rN may be used for another value on edges not going to BB. In this case, we "split" the critical edge. I.e. we create an empty block between P1 <https://reviews.llvm.org/P1> and BB on edge A and another between P2 <https://reviews.llvm.org/P2> and BB on edge B. This provides us with a place to insert the rN <- 42 and rN <- 37 instructions respectively.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88438/new/

https://reviews.llvm.org/D88438



More information about the llvm-commits mailing list