Open RKSimon opened 4 years ago
Also, we won't get the same x86 asm as gcc even with that transform in IR, so we may want to look at codegen first: https://c.godbolt.org/z/2d16-F
define zeroext i8 @rotl_better(i8 zeroext %x) {
%l = shl i8 %x, 2
%c = icmp slt i8 %x, 0
%o = call i8 @llvm.fshl.i8(i8 %x, i8 %x, i8 2)
%s = select i1 %c, i8 %l, i8 %o
ret i8 %s
}
rotl_better:
leal (,%rdi,4), %eax
movl %edi, %ecx
rolb $2, %cl
testb %dil, %dil
movzbl %al, %edx
movzbl %cl, %eax
cmovsl %edx, %eax
retq
If this is handled in IR, we'll need to canonicalize to the funnel shift intrinsic. We already have the opposite general transform:
define zeroext i8 @rotl(i8 zeroext %x) {
%l = shl i8 %x, 2
%r = lshr i8 %x, 6
%c = icmp slt i8 %x, 0
%o = or i8 %l, %r
%s = select i1 %c, i8 %l, i8 %o
ret i8 %s
}
Becomes:
define zeroext i8 @rotl_disguised(i8 zeroext %x) {
%l = shl i8 %x, 2
%r = lshr i8 %x, 6
%c = icmp slt i8 %x, 0
%s = select i1 %c, i8 0, i8 %r
%o = or i8 %s, %l
ret i8 %o
}
Extended Description
Not sure whether this can be done in instcombine or must wait until DAG.
https://c.godbolt.org/z/Pam6xk
we have a conditional use of a rotate pattern, which unfortunately gets broken up by the select
resulting in:
while gcc manages: