<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 --- - Instcombine generating i31s"
   href="https://llvm.org/bugs/show_bug.cgi?id=27343">27343</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Instcombine generating i31s
          </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>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>escha@apple.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>My impression is that instcombine isn't supposed to generate "weird" types that
are hard to handle later, like i31. In practice, this particular optimization
is creating the problem wherein CSE fails because there's some "trunc i32 to
i31" and some "and X, 0x7FFFFFFF" which in practice end up turning into the
same operation, but which are opaque to CSE. I figure the canonical one should
be the AND, not the weirdo i31 operation.

define i32 @__isnan(float %x) alwaysinline nounwind optsize {
entry:
  %x.addr = alloca float, align 4
  store float %x, float* %x.addr, align 4
  %0 = load float, float* %x.addr, align 4
  %1 = bitcast float %0 to i32 
  %shl = shl i32 %1, 1 
  %cmp = icmp ugt i32 %shl, -16777216
  %conv = zext i1 %cmp to i32 
  ret i32 %conv 
}

This optimizes to this:

; Function Attrs: alwaysinline nounwind optsize
define i32 @__isnan(float %x) #0 {
entry:
  %.cast = bitcast float %x to i32
  %0 = trunc i32 %.cast to i31
  %cmp = icmp ugt i31 %0, -8388608
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

which I don't think is what we want.</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>