From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0420E3858D37; Tue, 21 Nov 2023 22:03:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0420E3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700604186; bh=2BZaeV6lByqbU/PrUfC5i1egWnu/BqtU03AIbPeNP1U=; h=From:To:Subject:Date:From; b=kKCpLgGXeB/cm8+M3vyFB+oET1kjLHk2ty+F320o3YQTB7jBQ9m19xuki/xXCVo8Y fn71kjzEmnOSiCwp4LtzgI3hRrxIg5HQkZWueh+KArtMXQT/pMLjdFglMclw3OawE6 Gi/HPLoFJOiL/m6bWX9Ht9Ao98yBhtTRhywKWu6s= From: "goon.pri.low at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/112660] New: missed-optimization: combine shifts when shifted out bits are known 0 Date: Tue, 21 Nov 2023 22:03:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 13.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: goon.pri.low at gmail dot com 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=3D112660 Bug ID: 112660 Summary: missed-optimization: combine shifts when shifted out bits are known 0 Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: goon.pri.low at gmail dot com Target Milestone: --- This function here we know the shifted out bits have to be 0: int unopt(int v) { if (v & 3) return -1; return v >> 2 << 5; } unopt: test dil, 3 jne .L3 sar edi, 2 mov eax, edi sal eax, 5 ret .L3: mov eax, -1 ret Therefore we could combine the shifts: int opt(int v) { if (v & 3) return -1; return v << 3; } opt: test dil, 3 jne .L7 lea eax, [0+rdi*8] ret .L7: mov eax, -1 ret=