Bug 108756 - Unnecessary instruction
Summary: Unnecessary instruction
Status: RESOLVED DUPLICATE of bug 108516
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2023-02-10 22:00 UTC by Levo DeLellis
Modified: 2023-02-10 22:07 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Levo DeLellis 2023-02-10 22:00:10 UTC
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
Comment 1 Andrew Pinski 2023-02-10 22:07:24 UTC
Dup of bug 108516.

*** This bug has been marked as a duplicate of bug 108516 ***