<div dir="ltr">On Thu, Oct 1, 2015 at 11:06 PM, Philip Reames <span dir="ltr"><<a href="mailto:listmail@philipreames.com" target="_blank">listmail@philipreames.com</a>></span> wrote:<br><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    This looks like at least one missing case in SimplifyCFG most
    likely.  I suspect that our tail commoning code is being restricted
    to two incoming blocks to a phi, but that's just a guess.  Can you
    file a bug with the IR from your gist attached?<br></div></blockquote><div><br></div><div>Sorry, I forgot to reply to the list. I eventually found a bugreport which should be relevant: <a href="https://llvm.org/bugs/show_bug.cgi?id=24220">https://llvm.org/bugs/show_bug.cgi?id=24220</a><br></div><div>This other bug might be somewhat related <a href="https://llvm.org/bugs/show_bug.cgi?id=2056" target="_blank">https://llvm.org/bugs/show_bug.cgi?id=2056</a><br></div><div>AFAICT there is also some work on this here <a href="http://reviews.llvm.org/D14122">http://reviews.llvm.org/D14122</a> (but I did not understand if the patch has been abandoned or if it is stuck for some other reason).<br><br></div><div>Andrea<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div text="#000000" bgcolor="#FFFFFF">
    <br>
    Philip<div><div><br>
    <br>
    <div>On 09/30/2015 02:42 AM, Andrea Canciani
      via llvm-dev wrote:<br>
    </div>
    </div></div><blockquote type="cite"><div><div>
      <div dir="ltr">
        <div>Rust pattern matching code can sometimes generate very
          redundant LLVM IR, in which several branches contain exactly
          the same code.<br>
        </div>
        <div>LLVM successfully unifies that, but the dispatching
          mechanism does not simplify accordingly.<br>
          <br>
        </div>
        <div>I created a gist here:<br>
          <a href="https://gist.github.com/ranma42/d2e6d50999e801ffd4ed" target="_blank">https://gist.github.com/ranma42/d2e6d50999e801ffd4ed</a><br>
          (based on two examples available in Rust issues: <a href="https://github.com/rust-lang/rust/pull/24270#issuecomment-136681741" target="_blank"></a><a href="https://github.com/rust-lang/rust/pull/24270#issuecomment-136681741" target="_blank">https://github.com/rust-lang/rust/pull/24270#issuecomment-136681741</a><br>
          <a href="https://github.com/rust-lang/rust/issues/13623#issuecomment-136700526" target="_blank">https://github.com/rust-lang/rust/issues/13623#issuecomment-136700526</a>
          )<br>
          <br>
          In "enum4.s"<br>
          <br>
              cmpl    $1, %eax<br>
              je    LBB0_5<br>
              cmpl    $2, %eax<br>
              je    LBB0_5<br>
              cmpl    $3, %eax<br>
          LBB0_5:<br>
          <br>
        </div>
        <div>
          <div>could be removed.<br>
          </div>
          <div>(Further optimization would be possible by observing that
            the two 32-bit comparison could be unified into a single
            64-bit comparison, but I believe this is a different issue)<br>
          </div>
          <div><br>
          </div>
          <div>In "enum6.s" all of the elements of the jump table point
            to the same label (which is also right after the jump to the
            table dispatch code), so the jump table is actually useless.<br>
          </div>
          <div>
            <div><br>
            </div>
            <div>Is there any combination of passes that should make it
              possible for LLVM to optimize this?<br>
            </div>
            <div>Would outline + merge functions be a step in the right
              direction?<br>
            </div>
            <div>I googled for a similar thread in the mailing list and
              I found <a href="http://lists.llvm.org/pipermail/llvm-dev/2010-May/031629.html" target="_blank">http://lists.llvm.org/pipermail/llvm-dev/2010-May/031629.html</a><br>
            </div>
            <div>Unfortunately the thread does not provide a way to
              remove identical blocks in LLVM IR. Instead it suggests
              that this is only possible by relying on target-dependent
              optimizations. Does this mean that the best approach would
              be to make the target-dependent passes also optimize away
              jumps (when possible)?<br>
            </div>
            <div>I am somewhat afraid that this would prevent further
              optimizations that might be exposed by the removal of
              identical blocks (like the 32+32 -> 64 coalescing I
              mentioned before).<br>
            </div>
            <div><br>
            </div>
            <div>Andrea<br>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset></fieldset>
      <br>
      </div></div><pre>_______________________________________________
LLVM Developers mailing list
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
    <br>
  </div>

</blockquote></div><br></div></div></div>