<div dir="ltr">Here's an implementation that just uses nearest useful post dominator:<br><a href="https://github.com/apple/swift/blob/master/lib/SILOptimizer/Transforms/DeadCodeElimination.cpp">https://github.com/apple/swift/blob/master/lib/SILOptimizer/Transforms/DeadCodeElimination.cpp</a><br><div><br></div><div>Note the lack of needing to discover dead regions, etc.</div><div><br></div><div>(Rob Shillner's work here is unpublished, sadly)</div><div><br></div><div><br></div><div>There is a pseudocode version in <a href="https://yunmingzhang.files.wordpress.com/2013/12/dcereport-2.pdf">https://yunmingzhang.files.wordpress.com/2013/12/dcereport-2.pdf</a></div><div><br></div><div>Past that, if you can provide a simple example of the problem you are trying to solve with this code, i'm happy to try to help explain how this would work.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Oct 1, 2016 at 9:22 AM, Daniel Berlin <span dir="ltr"><<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">When I get back to a sane computer I'll send a link to the paper<div class="HOEnZb"><div class="h5"><br><br><div class="gmail_quote"><div dir="ltr">On Sat, Oct 1, 2016, 9:40 AM David Callahan <<a href="mailto:dcallahan@fb.com" target="_blank">dcallahan@fb.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">david2050 added inline comments.<br class="m_-3613500893762570951gmail_msg">
<br class="m_-3613500893762570951gmail_msg">
<br class="m_-3613500893762570951gmail_msg">
> dberlin wrote in ADCE.cpp:610<br class="m_-3613500893762570951gmail_msg">
> Is the above really necessary?<br class="m_-3613500893762570951gmail_msg">
><br class="m_-3613500893762570951gmail_msg">
> The standard way to do this, AFAIK, is to mark the useful block set while doing marking, and then just walking up the PDT to find the nearest block marked useful for each dead branch.<br class="m_-3613500893762570951gmail_msg">
> Replace all uses of the bb with that block using RAUW.<br class="m_-3613500893762570951gmail_msg">
> This should update phi nodes, since I believe the blocks in phi nodes are still considered uses.<br class="m_-3613500893762570951gmail_msg">
<br class="m_-3613500893762570951gmail_msg">
I don't understand this approach. Given a live branch  (x,y) where y is dead and  z is the live post-dominator of y, we can't just replace uses of 'y' because the 'y' may not be directly referenced in phi nodes in 'z' which only will old references to its predecessors. Also, 'y' could have multiple branches into it which are dead.<br class="m_-3613500893762570951gmail_msg">
<br class="m_-3613500893762570951gmail_msg">
<a href="https://reviews.llvm.org/D24918" rel="noreferrer" class="m_-3613500893762570951gmail_msg" target="_blank">https://reviews.llvm.org/<wbr>D24918</a><br class="m_-3613500893762570951gmail_msg">
<br class="m_-3613500893762570951gmail_msg">
<br class="m_-3613500893762570951gmail_msg">
<br class="m_-3613500893762570951gmail_msg">
</blockquote></div></div></div></blockquote></div><br></div>