<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 - Failure to combine rotate through a select"
   href="https://bugs.llvm.org/show_bug.cgi?id=45898">45898</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Failure to combine rotate through a select
          </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>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>Common Code Generator Code
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>llvm-dev@redking.me.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>lebedev.ri@gmail.com, llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Not sure whether this can be done in instcombine or must wait until DAG.

<a href="https://c.godbolt.org/z/Pam6xk">https://c.godbolt.org/z/Pam6xk</a>

#include <stdint.h>
uint8_t rotl_2(uint8_t x) {
  uint8_t Xlo = (x<<2);
  uint8_t Xhi = (x>>6);
  uint8_t Xrot = Xlo|Xhi;
  return (x < 128 ? Xrot : Xlo);
}

we have a conditional use of a rotate pattern, which unfortunately gets broken
up by the select

define zeroext i8 @rotl_2(i8 zeroext %0) {
  %2 = shl i8 %0, 2
  %3 = lshr i8 %0, 6
  %4 = icmp slt i8 %0, 0
  %5 = select i1 %4, i8 0, i8 %3
  %6 = or i8 %5, %2
  ret i8 %6
}

resulting in:

rotl_2:
        leal    (,%rdi,4), %ecx
        movl    %edi, %eax
        shrb    $6, %al
        xorl    %edx, %edx
        testb   %dil, %dil
        movzbl  %al, %eax
        cmovsl  %edx, %eax
        orb     %cl, %al
        retq

while gcc manages:

rotl_2:
        movl    %edi, %edx
        leal    0(,%rdi,4), %eax
        rolb    $2, %dl
        testb   %dil, %dil
        cmovns  %edx, %eax
        ret</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>