on-internet
← Community

Why does MSVC compile a structured binding of `std::pair` worse in `/std:c++20` than in `/std:c++latest`?

Stack Overflow ·

With MSVC x64 /O2, this function: #include <utility> float bindPair( std::pair<int, float> * s, int i ) { const auto [a, b] = s[i]; return a + b; } compiles differently depending on the language mode (https://godbolt.org/z/jhv6jf8aa). /std:c++20: the pair is loaded into a general-purpose register, stored to a stack temporary, and the float is read back from there: mov rdx, QWORD PTR [rcx+rax*8] mov QWORD PTR $T1[rsp], rdx ... cvtdq2ps xmm0, xmm0 addss xmm0, DWORD PTR $T1[rsp+4] /std:c++latest: both members are read directly from memory, as I would expect: ... cvtdq2ps xmm0, xmm0 addss xmm0, DW

Comments

Sign in or sign up to comment and upvote.

No comments yet.