Skip to content

Loop isn't optimized in pow() with constant power #34947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
eefriedman opened this issue Jul 21, 2016 · 2 comments
Closed

Loop isn't optimized in pow() with constant power #34947

eefriedman opened this issue Jul 21, 2016 · 2 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-slow Issue: Problems and improvements with respect to performance of generated code.

Comments

@eefriedman
Copy link
Contributor

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.

@steveklabnik steveklabnik added the I-slow Issue: Problems and improvements with respect to performance of generated code. label Jul 21, 2016
@Mark-Simulacrum
Copy link
Member

Assembly produced today is correct, and as expected. Closing.

0000000000000000 <_ZN4test1f17h2e3ee7790982a020E>:
   0:	89 f8                	mov    %edi,%eax
   2:	0f af c0             	imul   %eax,%eax
   5:	0f af f8             	imul   %eax,%edi
   8:	0f af f8             	imul   %eax,%edi
   b:	89 f8                	mov    %edi,%eax
   d:	c3                   	retq

@Mark-Simulacrum
Copy link
Member

Reopening as E-needstest. This should get a codegen test.

@Mark-Simulacrum Mark-Simulacrum added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label May 7, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 25, 2017
Dushistov added a commit to Dushistov/rust that referenced this issue Sep 2, 2017
bors added a commit that referenced this issue Sep 4, 2017
add test for not optimized `pow` with constant power

Closes #34947
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-slow Issue: Problems and improvements with respect to performance of generated code.
Projects
None yet
Development

No branches or pull requests

3 participants