<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - GVNHoist illegally hoists div instruction"
   href="https://llvm.org/bugs/show_bug.cgi?id=31729">31729</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>GVNHoist illegally hoists div instruction
          </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>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>matze@braunis.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=17884" name="attach_17884" title="C reproducer">attachment 17884</a> <a href="attachment.cgi?id=17884&action=edit" title="C reproducer">[details]</a></span>
C reproducer

The attached testcase performs a division (by zero) before checking the
condition present in the original sourcecode. The problem appears when
compiling test-suite/SingleSource/UnitTests/SignlessTypes/rem.c with the -Oz
flag.

I reduced the test to a small reproducer and will attach them here. Looking at
the -print-after-all output it seems GVNHoist is to blame and the problem goes
away with -gvn-max-hoisted=0 for me.

I can reproduce this on a macOS system with:

$ clang -Oz reduced.c
$ ./a.out
Floating point exception: 8

I attached a -O0 -emit-llvm .ll file for convenience but did not test whether
that reproduces as well.</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>