Closed
Description
Testcase:
pub fn f(x: i32) -> i32 { x.pow(5) }
Produces the following asm in release mode:
_ZN8rust_out1f17hc690d9db51fd1099E:
.cfi_startproc
movl $5, %ecx
movl $1, %r8d
movl $1, %eax
.align 16, 0x90
.LBB0_1:
movl %ecx, %esi
testb $1, %sil
movl %edi, %edx
cmovel %r8d, %edx
imull %edx, %eax
shrl %ecx
imull %edi, %edi
cmpl $3, %esi
ja .LBB0_1
cmpl $1, %ecx
movl $1, %ecx
cmovel %edi, %ecx
imull %ecx, %eax
retq
I would expect it to generate straight-line code with just three multiplies.
It's possible this will be fixed by upgrading LLVM; there have been some recent changes to unrolling heuristics.