https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108756
Bug ID: 108756
Summary: Unnecessary instruction
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: levo.delellis at gmail dot com
Target Milestone: ---
You can test this on godbolt. Using gcc 12.2 on x86-64 linux
There appears to be an unnecessary instruction. I commented the assembly below
struct T2 { bool a, b; };
static T2 test();
int myfunc() {
auto [a, b] = test();
return ((int)a<<1) + b;
}
Result
myfunc():
sub rsp, 8
call test() <-- Result is b<<8 | a
add rsp, 8
movzx edx, al <--- moves a
movzx eax, ah <--- extends b into itself
movzx eax, al <--- Huh?
lea eax, [rax+rdx*2]
ret