<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Non-deterministic result due to use of SmallPtrSet in llvm::removeUnreachableBlocks"
   href="https://bugs.llvm.org/show_bug.cgi?id=42574">42574</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Non-deterministic result due to use of SmallPtrSet in llvm::removeUnreachableBlocks
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Transformation Utilities
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mikael.holmen@ericsson.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=22222" name="attach_22222" title="reproducer">attachment 22222</a> <a href="attachment.cgi?id=22222&action=edit" title="reproducer">[details]</a></span>
reproducer

Running

 opt -simplifycfg  -o foo.ll in3.ll -S --preserve-ll-uselistorder

a number of times with a clang 8 built opt we see that the produced output
differs now and then like:

 <   uselistorder i16 0, { 2, 3, 4, 1, 5, 0, 6 }
 ---
 >   uselistorder i16 0, { 3, 2, 4, 1, 5, 0, 6 }

I think it's the DeadBlockSet that is the cause:

-  // Loop over all of the basic blocks that are not reachable, dropping all of
-  // their internal references. Update DTU and LVI if available.
-  std::vector <DominatorTree::UpdateType> Updates;
+  SmallPtrSet<BasicBlock *, 16> DeadBlockSet;

As far as I can see, as long as a SmallPtrSet is "small", the iteration order
is deterministic (== insertion order), but I strongly suspect that when the set
grows to being "big", then it's not deterministic anymore.

DeadBlockSet as above was introduced in r339951:

    Update MemorySSA in Local utils removing blocks.

    Summary: Extend Local utils to update MemorySSA.

    Subscribers: sanjoy, jlebar, Prazek, george.burgess.iv, llvm-commits

    Differential Revision: <a href="https://reviews.llvm.org/D48790">https://reviews.llvm.org/D48790</a>

    llvm-svn: 339951


Later this caused SCEV and LSR in llc to draw different conclusions and
produce different code.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>