From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 61590385DC0B; Thu, 14 May 2020 09:10:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61590385DC0B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1589447437; bh=CgFJUYZwZMbsTHQJNDCD3f3afIp8A6sMB6swrSvI35s=; h=From:To:Subject:Date:In-Reply-To:References:From; b=XvBd2pL7ZafDH7cgN/P+lEs0dFndOUIdNbaaXY1l1CQfMQd6rkmlRAvMKPYca8kZw TJxUtmKn6cR7xG3ANkfCKm5RvGo8fEAOAfTjhJNgWw3eCvEEPcMmJPAIorvynOZuLl 2ZeB8M5sNmspe81x2DOClZ3vkBbXq9auCNgRosiE= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/94703] Small-sized memcpy leading to unnecessary register spillage unless done through a dummy union Date: Thu, 14 May 2020 09:10:37 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: REOPENED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 May 2020 09:10:37 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94703 --- Comment #12 from Richard Biener --- (In reply to pskocik from comment #11) > Thanks for the shot at a fix, Richard Biener. >=20 > Since I have reported this, I think I should mentioned a related > suboptimality that should probably be getting fixed alongside with this (= if > this one is getting fixed), namely that while >=20 >=20 > int64_t zextend_int_to_int64_nospill(int *X)=20 > {=20 > union { int64_t _; } r =3D {0}; return memcpy(&r._,X,sizeof(*X)),r._; > } >=20 > (and hopefully later even=20 >=20 > int64_t zextend_int_to_int64_spill(int *X) { int64_t r =3D {0}; return > memcpy(&r,X,sizeof(*X)),r; } > ) >=20 > generates, on x86_64, the optimal >=20 > zextend_int_to_int64_nospill: > mov eax, DWORD PTR [rdi] > ret >=20 > for zeroextending promotions of sub-int types, an extra xor instruction g= ets > generated, e.g.: >=20 >=20 > int64_t zextend_short_to_int64_nospill_but_suboptimal(short *X)=20 > { > union { int64_t _; } r =3D{0}; return memcpy(&r._,X,sizeof(*X)),r._; > } >=20 > =3D> >=20 > zextend_short_to_int64_nospill_but_suboptimal: > xor eax, eax > mov ax, WORD PTR [rdi] > ret >=20 > which was surprising to me because it doesn't happen with zero-extending > memcpy-based promotion from {,u}ints to larger types ({,u}{,l}longs). >=20 > https://gcc.godbolt.org/z/ZjXaCw I think this is PR93507 for which I have a patch queued as well.=