<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 - [InstCombine] icmp with sdiv operand transformed strangely"
   href="https://bugs.llvm.org/show_bug.cgi?id=36240">36240</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[InstCombine] icmp with sdiv operand transformed strangely
          </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>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>spatel+llvm@rotateright.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>define i1 @cmpdiv(i32 %x) {
  %d = sdiv i32 1, %x
  %c = icmp slt i32 %d, 0
  ret i1 %c
}

$ opt -instcombine cmpsignbit.ll -S
define i1 @cmpdiv(i32 %x) {
  %1 = add i32 %x, 1
  %2 = icmp ult i32 %1, 3
  %c1 = icmp slt i32 %x, 0
  %c = and i1 %2, %c1
  ret i1 %c

That's a weird way to write:
  %c = icmp eq i32 %x, -1

-------------------------------------------------------------------------------

Note that we don't do anything with this case:

define i1 @cmpdiv400(i32 %x) {
  %d = sdiv i32 400, %x
  %c = icmp slt i32 %d, 0
  ret i1 %c
}

But we could turn this into a range check:

Name: sdiv400
  %d = sdiv i32 400, %x
  %c = icmp slt i32 %d, 0
=>
 %c1 = icmp sge i32 %x, -400  
 %c2 = icmp slt i32 %x, 0
 %c = and i1 %c1, %c2 

<a href="https://rise4fun.com/Alive/cDM">https://rise4fun.com/Alive/cDM</a>

...so whatever is trying to improve the 1st case could probably use
generalizing and fixing.</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>