<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Turns out it wasn't a bug, but a very contrived set-up.</p>
    <p>When the peephole optimiser is turned off completely, the
      following is revealed:</p>
    <p>    je    .Lj371<br>
          jmp    .Lj372<br>
      .Lj371:<br>
          movl    $3,%r14d<br>
          movl    $1,%r15d<br>
          jmp    .Lj373<br>
          .p2align 4,,10<br>
          .p2align 3<br>
      .Lj372:<br>
          jmp    .Lj333<br>
      .Lj373:<br>
      .Lj370:<br>
      .Lj367:<br>
         ...<br>
    </p>
    <p>What happens is that the optimiser changes "je .Lj371; jmp
      .Lj372; .Lj371:" into "jne .Lj372" (what I call a 'conditional
      jump inversion'), and then the final destination is tracked: the
      compiler notices that after "jne .Lj372", the program flow
      immediately stumbles upon an unconditional jump ("jmp .Lj333"), so
      it changes the destination to match, thus it becomes "jne
      .Lj333".  After all of this, .Lj372 becomes a dead label, and when
      the optimiser reaches "jmp .Lj373", it removes all the dead code
      between it and the next live label, since it will never be
      executed; this includes the original "jmp .Lj333" instruction
      because .Lj372 is no longer referenced by anything (Then "jmp
      .Lj373" is removed as well because the destination label is right
      after it once everything is stripped).  As such, because .Lj372 is
      a dead label and there are no other (live) labels in that cluster,
      it correctly removes the alignment fields... in other words, the
      remaining labels were never actually aligned - it was just a
      coincidence they became aligned before.</p>
    <p>Gareth aka. Kit<br>
    </p>
    <div class="moz-cite-prefix">On 01/11/2019 14:11, Sven Barth via
      fpc-devel wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAFMUeB8Dvifm19H3gdXPv6Zc0M7OWcjhEo1rt7=-aoyGrHH3ew@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="auto">
        <div>
          <div class="gmail_quote">
            <div dir="ltr" class="gmail_attr">J. Gareth Moreton <<a
                href="mailto:gareth@moreton-family.com"
                moz-do-not-send="true">gareth@moreton-family.com</a>>
              schrieb am Fr., 1. Nov. 2019, 12:56:<br>
            </div>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">So the
              tests all passed on i386-win32 and x86_64-win64, so that's
              s a <br>
              good sign.  I can't submit the patches for evaluation yet
              because I <br>
              haven't finished the design spec yet, and also because of
              a minor bug <br>
              that deals with collapsing label clusters:<br>
              <br>
                   .p2align 4,,10<br>
                   .p2align 3<br>
              .Lj370:<br>
              .Lj367:<br>
              .Lj364:<br>
              .Lj361:<br>
              .Lj358:<br>
              .Lj355:<br>
              .Lj352:<br>
              .Lj349:<br>
              .Lj346:<br>
              .Lj343:<br>
              .Lj340:<br>
              <br>
              In this segment, everything is stripped except for the
              last label, which <br>
              is fine as all the references are changed too.
              Unfortunately, the <br>
              alignment fields are removed too, which shouldn't happen. 
              It doesn't <br>
              produce incorrect code, but it may incur a performance
              penalty, so <br>
              shouldn't be removed - I'm just trying to figure out why
              that's happening!<br>
            </blockquote>
          </div>
        </div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">Considering that you said that this feature is
          essentially cross platform: on some other platform the
          alignments might be important beside performance (e.g. a
          branch inside a branch delay slot or something like that). So,
          yeah, that should be fixed... </div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">Regards, </div>
        <div dir="auto">Sven </div>
        <div dir="auto">
          <div class="gmail_quote">
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">
            </blockquote>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
fpc-devel maillist  -  <a class="moz-txt-link-abbreviated" href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
</pre>
    </blockquote>
  </body>
</html>