Skip to content
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

Unnecessary fsqrt of 0.0 #110589

Open
Kmeakin opened this issue Sep 30, 2024 · 0 comments
Open

Unnecessary fsqrt of 0.0 #110589

Kmeakin opened this issue Sep 30, 2024 · 0 comments

Comments

@Kmeakin
Copy link
Contributor

Kmeakin commented Sep 30, 2024

https://godbolt.org/z/s4T3dc6ae

pub fn sqrt_of_sum(xs: &[f64]) -> f64 {
    xs.iter().sum::<f64>().sqrt()
}
example::sqrt_of_sum::h8605ab463220c776:
        cbz     x1, .LBB0_3
        cmp     x1, #4
        b.hs    .LBB0_4
        mov     x9, #-9223372036854775808
        mov     x8, xzr
        fmov    d0, x9
        b       .LBB0_7
.LBB0_3:
        mov     x8, #-9223372036854775808
        fmov    d0, x8
        fsqrt   d0, d0
        ret
...

The main loop body is not important here, we are concerned with the early return in the len == 0 case. Here, we load 0.0 into x8 and fsqrt it; but we could just return 0.0 directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants