[PATCH] D29916: [CGP] Split some critical edges coming out of indirect branches

Michael Kuperstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 13 18:10:58 PST 2017


mkuper added a comment.

In https://reviews.llvm.org/D29916#675801, @efriedma wrote:

> > I don't really understand what you mean regarding splitting the other predecessors. I want to avoid having a phi on a block where one of the predecessor blocks on the phi is an indirectbr. I don't see how doing anything to the other incoming edges would help, you'll still end  with this phi, just change the other predecessors.
>
> Err, sorry, that was a terrible explanation; I started out thinking one thing, and writing something different.
>
> Anyway, suppose you have a block B with one indirectbr predecessor and some other non-indirectbr predecessors.  First, you split `B` before the first non-PHI instruction, making `B2`.  Then you clone `B`, making `B3`.  Then you change all the non-indirectbr predecessors of `B` point at `B3`.  (Then you fix up the PHI nodes.)  You now have exactly the same CFG as your code produces, without messing with the global variable.


Oh, got it! That's really nice, thanks!

>> Regardless, I'd like to also extend this to split cases where we have several indirectbr predecessors (of this form).
> 
> clang doesn't generate code like that, even if a function has multiple indirect goto statements.  Have you seen this come up in practice?

No, I haven't seen that, it was just the generalization step that seemed obvious to me. You're right, it's probably better to generalize in the direction you suggested above.
I'll try that and see if anything unexpected breaks.


https://reviews.llvm.org/D29916





More information about the llvm-commits mailing list