<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] missing folds for bit manipulation intrinsics"
   href="https://llvm.org/bugs/show_bug.cgi?id=28668">28668</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[InstCombine] missing folds for bit manipulation intrinsics
          </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>spatel+llvm@rotateright.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>define i1 @ctlz_cmp(i32 %a) {
  %x = tail call i32 @llvm.ctlz.i32(i32 %a, i1 false) #0
  %cmp = icmp eq i32 %x, 0  ; no zeros? --> all ones
  ret i1 %cmp
}

define i1 @cttz_cmp(i32 %a) {
  %x = tail call i32 @llvm.cttz.i32(i32 %a, i1 false) #0
  %cmp = icmp eq i32 %x, 0  ; no zeros? --> all ones
  ret i1 %cmp
}

define i1 @ctpop_cmp(i32 %a) {
  %x = tail call i32 @llvm.ctpop.i32(i32 %a) #0
  %cmp = icmp eq i32 %x, 32 ; all ones? --> no zeros
  ret i1 %cmp
}

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

$ ./opt -instcombine more_bitz.ll -S

(doesn't change anything)

Note that these all work:

define i1 @ctlz_cmp(i32 %a) {
  %x = tail call i32 @llvm.ctlz.i32(i32 %a, i1 false) nounwind readnone
  %cmp = icmp eq i32 %x, 32  ; all zeros? --> no ones
  ret i1 %cmp
}

define i1 @cttz_cmp(i32 %a) {
  %x = tail call i32 @llvm.cttz.i32(i32 %a, i1 false) nounwind readnone
  %cmp = icmp eq i32 %x, 32  ; all zeros? --> no ones
  ret i1 %cmp
}

define i1 @ctpop_cmp(i32 %a) {
  %x = tail call i32 @llvm.ctpop.i32(i32 %a) nounwind readnone
  %cmp = icmp eq i32 %x, 0   ; no ones? --> all zeros
  ret i1 %cmp
}

$ ./opt -instcombine more_bitz.ll -S
...
define i1 @ctlz_cmp(i32 %a) {
  %cmp = icmp eq i32 %a, 0
  ret i1 %cmp
}

define i1 @cttz_cmp(i32 %a) {
  %cmp = icmp eq i32 %a, 0
  ret i1 %cmp
}

define i1 @ctpop_cmp(i32 %a) {
  %cmp = icmp eq i32 %a, 0
  ret i1 %cmp
}</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>