From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0C2693858436; Wed, 11 Oct 2023 07:09:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0C2693858436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697008148; bh=3weJjoWWjKLxyiN+tq+G8XK7XeAiiu3RfgHtVyF1/LY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QOqn/kYVDNwClq8hTHx91F4huGq5M83bkzD3jnEGUMd/D5cxOx4P9YVwRf8f3P3/q Euli+R3LiQXiJGU3TSeJV2NE127UCNqLuvOV6D7Sd6jXchlqPWn1C9fR/O11Vi7rUo aIoLiOLJva7WV6jGQpfeYLKGzrhusgMShqsAfnBw= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/101955] (signed<<31)>>31 should become -(signed&1) Date: Wed, 11 Oct 2023 07:09:06 +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: 12.0 X-Bugzilla-Keywords: easyhack, missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: NEW 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: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101955 --- Comment #7 from CVS Commits --- The master branch has been updated by Roger Sayle : https://gcc.gnu.org/g:c41492423140e1573df68d1c98e825ae7593741f commit r14-4551-gc41492423140e1573df68d1c98e825ae7593741f Author: Roger Sayle Date: Wed Oct 11 08:08:04 2023 +0100 Optimize (ne:SI (subreg:QI (ashift:SI x 7) 0) 0) as (and:SI x 1). This patch is the middle-end piece of an improvement to PRs 101955 and 106245, that adds a missing simplification to the RTL optimizers. This transformation is to simplify (char)(x << 7) !=3D 0 as x & 1. Technically, the cast can be any truncation, where shift is by one less than the narrower type's precision, setting the most significant (only) bit from the least significant bit. This transformation applies to any target, but it's easy to see (and add a new test case) on x86, where the following function: int f(int a) { return (a << 31) >> 31; } currently gets compiled with -O2 to: foo: movl %edi, %eax sall $7, %eax sarb $7, %al movsbl %al, %eax ret but with this patch, we now generate the slightly simpler. foo: movl %edi, %eax sall $31, %eax sarl $31, %eax ret 2023-10-11 Roger Sayle gcc/ChangeLog PR middle-end/101955 PR tree-optimization/106245 * simplify-rtx.cc (simplify_relational_operation_1): Simplify the RTL (ne:SI (subreg:QI (ashift:SI x 7) 0) 0) to (and:SI x 1). gcc/testsuite/ChangeLog * gcc.target/i386/pr106245-1.c: New test case.=