[PATCH] D117805: [SimplifyCFG] Merge compatible `invoke`s of a `landingpad`

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 20 09:49:20 PST 2022


lebedev.ri created this revision.
lebedev.ri added reviewers: rnk, jcranmer, jdoerfert, efriedma, nikic.
lebedev.ri added a project: LLVM.
Herald added a subscriber: hiraditya.
lebedev.ri requested review of this revision.

While nowadays SimplifyCFG knows how to hoist code from then-else blocks,
sink code from unconditional predecessors, and even promote the latter
by tail-merging `ret`/`resume` function terminators, that isn't everything.

While i (& others) have been trying to deal with merging/sinking `unreachable`,
apparently perhaps the more impactful remaining problem is merging the `throw`
calls.

If we start at the `landingpad`, all the predecessors are unwind edges of `invoke`s,
and in some cases some of the `invoke`s are mergeable.

  /// This is a weird mix of hoisting and sinking. Visually, it goes from:
  ///          [...]        [...]
  ///            |            |
  ///        [invoke0]    [invoke1]
  ///           / \          / \
  ///     [cont0] [landingpad] [cont1]
  /// to:
  ///      [...] [...]
  ///          \ /
  ///       [invoke]
  ///          / \
  ///     [cont] [landingpad]

This simplifies the IR/CFG, at the cost of debug info and extra PHI nodes.

Note that we don't require for *all* the `invokes` of the `landingpad`
to be mergeable, they can form more than a single set, we gracefully handle that.

For now, i completely disallowed normal destination, PHI nodes and indirect invokes
but that can be supported.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117805

Files:
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/SimplifyCFG/X86/merge-compatible-invokes-of-landingpad-debuginfo.ll
  llvm/test/Transforms/SimplifyCFG/X86/merge-compatible-invokes-of-landingpad.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117805.401672.patch
Type: text/x-patch
Size: 31043 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220120/474c8979/attachment.bin>


More information about the llvm-commits mailing list