<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 --- - Reassociate wrongly preserves nuw" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D23926&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=wWxdXLcnx_3F0TsURXEbVGoh-g-57OhmZvFGGNHerrk&s=-eRBMyaaQqh2s_fDGMBki2gD2FFSeSn7Tw3mDRlbPBI&e=">23926</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Reassociate wrongly preserves nuw
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Keywords</th>
          <td>miscompilation
          </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>nunoplopes@sapo.pt
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>david.majnemer@gmail.com, llvmbugs@cs.uiuc.edu, regehr@cs.utah.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ cat bug.ll
define i2 @func78000101(i2, i2) {
  %3 = add nuw i2 %0, 1
  %4 = sub nuw nsw i2 %1, %3
  ret i2 %4
}


$ opt -reassociate -S bug.ll
define i2 @func78000101(i2, i2) {
  %.neg = sub i2 0, %0
  %.neg1 = add nuw i2 %.neg, -1
  %3 = add i2 %.neg1, %1
  ret i2 %3
}


$ ./alive.py bug.opt
----------------------------------------
Optimization: func78000101
Precondition: true
  %3 = add nuw i2 %0, 1
  %4 = sub nuw nsw i2 %1, %3
  ret i2 %4
=>
  %.neg = sub i2 0, %0
  %.neg1 = add nuw i2 %.neg, -1
  %3 = add i2 %.neg1, %1
  ret i2 %3


ERROR: Domain of undefinedness of Target is smaller than Source's for i2 %3

Example:
%0 i2 = 0x2 (2, -2)
%1 i2 = 0x0 (0)
%.neg i2 = 0x2 (2, -2)
%.neg1 i2 = 0x1 (1)
Undef inputs: %1
Source value: 0x3 (3, -1)
Target value: undef</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>