From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 603C3385AFAC; Tue, 18 Jul 2023 14:32:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 603C3385AFAC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689690738; bh=+L/Zo6NzaZlYORehreSu6KXJ2Oq7SI/6dDMTrB1/FFw=; h=From:To:Subject:Date:From; b=VuxlafLXWXXlGJJP7Va9v0L5/xVajU94UQrq12Q6bZ0P/k3bbCEif4ZSuC3gsp5Jn jnmDPFNRat9+yXlnpXuVflScCP0AkQqNZcP3uZ7zTz+TbFarPzbXRXYQmDe0XrzPTR PrzAi9Ffu6aCZfnRUMZ8Oa2kYFsXfRUpDPoSQsPI= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/110717] New: Double-word sign-extension missed-optimization Date: Tue, 18 Jul 2023 14:32:17 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110717 Bug ID: 110717 Summary: Double-word sign-extension missed-optimization Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: jakub at gcc dot gnu.org Target Milestone: --- While working on _BitInt, I've noticed that we don't emit very good code at least on x86_64 -m64/-m32 -O2 for: #ifdef __SIZEOF_INT128__ unsigned __int128 foo (unsigned __int128 x) { x <<=3D 59; return ((__int128) x) >> 59; } #else unsigned long long foo (unsigned long long x) { x <<=3D 27; return ((long long) x) >> 27; } #endif The sign-extension from 69 resp. 37 bits could be limited solely to the upp= er word, but we uselessly shift the lower word with it as well: movq %rdi, %rax movq %rsi, %rdx shldq $59, %rdi, %rdx salq $59, %rax shrdq $59, %rdx, %rax sarq $59, %rdx ret for -m64 and movl 4(%esp), %eax movl 8(%esp), %edx shldl $27, %eax, %edx sall $27, %eax shrdl $27, %edx, %eax sarl $27, %edx ret for -m32. LLVM emits even more horrible code for -m64, but movl 4(%esp), %eax movl 8(%esp), %edx shll $27, %edx sarl $27, %edx retl for -m32, which looks to me like what we want.=