[llvm-bugs] [Bug 45898] New: Failure to combine rotate through a select

via llvm-bugs llvm-bugs at lists.llvm.org
Wed May 13 03:54:40 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=45898

            Bug ID: 45898
           Summary: Failure to combine rotate through a select
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: llvm-dev at redking.me.uk
                CC: lebedev.ri at gmail.com, llvm-bugs at lists.llvm.org,
                    spatel+llvm at rotateright.com

Not sure whether this can be done in instcombine or must wait until DAG.

https://c.godbolt.org/z/Pam6xk

#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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200513/734f004e/attachment.html>


More information about the llvm-bugs mailing list