<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 produces worse code when provided with range information"
   href="https://bugs.llvm.org/show_bug.cgi?id=37636">37636</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>InstCombine produces worse code when provided with range information
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>max.kazantsev@azul.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Instcombine can sometimes produce a worse code when dealing with values
annotated by ranges than if there was no range. Apparently it tries to replace
sdiv with bit magic and it breaks some other pattern recognition.

Tests:

define i1 @good(i32* %A) {
  %A.val = load i32, i32* %A, align 8
  %B = sdiv i32 %A.val, 2
  %C = icmp sge i32 0, %B
  ret i1 %C
}

define i1 @bad(i32* %A) {
  %A.val = load i32, i32* %A, align 8, !range !0
  %B = sdiv i32 %A.val, 2
  %C = icmp sge i32 0, %B
  ret i1 %C
}

!0 = !{i32 0, i32 2147483647}

Run opt -instcombine -S

The result is:

define i1 @good(i32* %A) {
  %A.val = load i32, i32* %A, align 8
  %C = icmp slt i32 %A.val, 2
  ret i1 %C
}

define i1 @bad(i32* %A) {
  %A.val = load i32, i32* %A, align 8, !range !0
  %B.mask = and i32 %A.val, 2147483646
  %C = icmp eq i32 %B.mask, 0
  ret i1 %C
}

!0 = !{i32 0, i32 2147483647}</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>