<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 --- - The add instruction is incorrectly folded into icmp when there is an overflow by instcombine"
   href="https://llvm.org/bugs/show_bug.cgi?id=25986">25986</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>The add instruction is incorrectly folded into icmp when there is an overflow by instcombine
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.7
          </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>normal
          </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>yuanrui.zhang@intel.com
          </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>Given the following reduced test:

define i32 @f(i32 %j) {
entry:
  %inc = add nsw i32 %j, 1
  %cmp = icmp sgt i32 %inc, 0
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

define i32 @main() {
entry:
  %call = call i32 @f(i32 2147483647)
  ret i32 0
}

InstCombine folds the following 2 instructions

  %inc = add nsw i32 %j, 1
  %cmp = icmp sgt i32 %inc, 0

into:

 <badref> = icmp sgt i32 %j, -1

and the IR becomes wrong after InstCombine as below:


define i32 @f(i32 %j) {
entry:
  %j.lobit = lshr i32 %j, 31
  %j.lobit.not = xor i32 %j.lobit, 1
  ret i32 %j.lobit.not
}

define i32 @main() {
entry:
  %call = call i32 @f(i32 2147483647)
  ret i32 0
}

The error comes from visitICmpInst</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>