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

Suboptimal assembly for struct equality #8391

Open
rafihayne opened this issue Mar 29, 2021 · 2 comments
Open

Suboptimal assembly for struct equality #8391

rafihayne opened this issue Mar 29, 2021 · 2 comments
Milestone

Comments

@rafihayne
Copy link

rafihayne commented Mar 29, 2021

I stumbled across this issue in the rust compiler and started playing with it in zig. With some help of @lithdew, it appears that similarly to rust, zig does not vectorize the function call. We tried with std.meta.eql, but the current zig implementation seems like a much more simple reproduction case

Zig Godbolt
C++ Godbolt

Unfortunately I don't know enough about compilers to debug further. If folks have an idea for how to dig into this, happy to learn and give it a shot with some advice.

It looks like there may be some difference between C++ pointers and references
https://godbolt.org/z/qaGfYf95j

@lithdew
Copy link
Contributor

lithdew commented Mar 29, 2021

The issue appears to come down to how passing by reference and passing by pointer differs in C++. Zig automatically assumes passing by pointer for function arguments, and therefore can't vectorize as well in comparison to passing by reference like in C++.

Here's the difference in assembly between passing by reference and passing by pointer in C++: https://godbolt.org/z/WYc1W489r

@LemonBoy
Copy link
Contributor

The issue appears to come down to how passing by reference and passing by pointer differs in C++.

Not really. The problem is that the emitted IR is too convoluted and is failing to trigger the mergeicmps pass, Clang's IR manages to get all the comparisons to be folded into a single memcmp that's then expanded into vectorized ops.

@Vexu Vexu added this to the 0.9.0 milestone Mar 30, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
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

5 participants