https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87062
Bug ID: 87062 Summary: mis-optimized code with -O3 and std::pair Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: tromey at gcc dot gnu.org Target Milestone: --- I'm filing this on behalf of someone who posted this bug on reddit. https://www.reddit.com/r/cpp/comments/99e1ri/interesting_gcc_optimizer_bug/ Copying text from there: Looks like there is an interesting gcc optimizer bug in gcc 7+. #include <utility> std::pair<long, long> fret(long i) { return {i, i}; } With -O2 gcc generates the expected: mov rdx, rdi mov rax, rdi But with -O3 it generates: mov QWORD PTR [rsp-24], rdi movq xmm0, QWORD PTR [rsp-24] punpcklqdq xmm0, xmm0 movaps XMMWORD PTR [rsp-24], xmm0 mov rax, QWORD PTR [rsp-24] mov rdx, QWORD PTR [rsp-16] https://godbolt.org/z/lXoaA4