From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7E7CB3858D20; Sun, 21 May 2023 05:36:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E7CB3858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684647395; bh=cMbCMFSSxmZagznFavvfp1NnG5zNfcFnvfNFFTcxfB8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KpWYVXGx2p7gGmbg25jlJn+eGWnCaNrxHyzsMmKLR4grKzk+l9RcBjG0n9b+4zLJr w/sG99lv+bpa9rlGeuNVHTBedVTlAzN3eVeP+Axld9xpp64peKTpehpUTFMr0u6EyM H2/qs8W5FRo1EgYK5KCXce/c9ARPYkYejhu1ohpE= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/109907] Missed optimization for bit extraction (uses shift instead of single bit-test) Date: Sun, 21 May 2023 05:36:35 +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: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia 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=3D109907 --- Comment #16 from Andrew Pinski --- (In reply to Andrew Pinski from comment #14) > Actually I take back on what is going on those 3. But I will be looking i= nto > it. >=20 >=20 > x.0_1 =3D (signed long) x_4(D); > _2 =3D x.0_1 >> 31; > _3 =3D (unsigned char) _2; > _5 =3D _3 & 1; we could pattern match this on the gimple using something like: (simplify (bit_and (convert? (rshift (nop_convert? @1) INTEGER_CST@2)) integer_onep) (if (wi::to_wide (@2) =3D=3D TYPE_PRECISION (TREE_TYPE (@0)) - 1) (with { tree utype =3D unsigned_type_for (type); } (convert (rshift (convert:utype @1) @2))) But that still fails because combine really does not like subregs: Trying 6 -> 12: 6: r47:SI=3Dr48:SI 0>>0x1f REG_DEAD r48:SI 12: r24:QI=3Dr47:SI#0 REG_DEAD r47:SI Failed to match this instruction: (set (reg/i:QI 24 r24) (subreg:QI (lshiftrt:SI (reg:SI 48) (const_int 31 [0x1f])) 0))=