<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 - Canonicalize (-X srem Y) to -(X srem Y)"
   href="https://bugs.llvm.org/show_bug.cgi?id=41443">41443</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Canonicalize (-X srem Y) to -(X srem Y)
          </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>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>chenzheng1030@hotmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This is from code review comment of <a href="https://reviews.llvm.org/D60395">https://reviews.llvm.org/D60395</a>
In that patch, canonicalization is done for '-X s/ Y', so it can save one div
for -(X/Y) and (-X/Y).

There should be same opportunity for srem.

----------------------------------------
Optimization: -X srem Y -> -(X srem Y)
Precondition: true
  %o0 = sub nsw i8 0, %x
  %r = srem i8 %o0, %y
=>
  %n0 = srem i8 %x, %y
  %r = sub nsw i8 0, %n0
Done: 1                                                                         
Optimization is correct


(X srem -Y) is not equal to -(X srem Y).

----------------------------------------
Optimization: X srem -Y -> -(X srem Y)
Precondition: true
  %t0 = sub nsw i8 0, %y
  %r  = sdiv i8 %x, %t0
=>
  %n0 = sdiv i8 %x, %y
  %r  = sub i8 0, %n0

ERROR: Target introduces undefined behavior for i8 %r                           

Example:
i8 %x  = poison
i8 %y  = 0xff (255, -1)
i8 %t0 = 0x01 (1)
source: poison
target: undefined</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>