From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2D4C83858C83; Mon, 24 Apr 2023 07:02:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D4C83858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682319750; bh=1YTHyF7xiMDRR/sRYsg9DA5A80YhBcS2e8td8X0FJdM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FXibGdGl5EfJ+JJ+P8i5ENvUACwibQfMCKj66jF8YY4WZlBEomoAIduV0g8WVvyg7 hMxkKsaCiP9br1koMNFzs/PwTfzRnSUBuoUDE+uQH8tOCQCitsS5rh/o8qBqDeHJtC /BIuxnXPQ3jBpadDWRDPWgyjsYUdvTCNSmnLfN04= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/109592] Failure to recognize shifts as sign/zero extension Date: Mon, 24 Apr 2023 07:02:29 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth 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: cf_reconfirmed_on bug_status everconfirmed keywords 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=3D109592 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2023-04-24 Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Keywords| |missed-optimization --- Comment #3 from Richard Biener --- (In reply to Jeffrey A. Law from comment #0) > This is a trivial sign extension: >=20 > int sextb32(int x) > { return (x << 24) >> 24; } Btw, during the various attempts at GIMPLE narrowing/widening passes we thought it might be interesting to add {S,Z}EXT_EXPR to GIMPLE. For ZEXT_EXPR the canonical variant is currently a BIT_AND_EXPR with an appropriate mask, so ZEXT_EXPR wouldn't be any shorter (thus I'm not sure we want to add it). For SEXT_EXPR the canonical form is truncation to signed and then a sign extending cast - thus two conversions. But at least I don't see the above being canonicalized to that (not sure if it would help RTL expansion). We fail to simplify int sextb32(int x) { return (x << 24) >> 24 =3D=3D (int)(signed char)x; } because of the missed canonicalization. Note for (x << 27) >> 27 we'd end up with bit-precision casts which is ugly and likely unwanted. A SEXT_EXPR (x, 8) (the extend-from bit position would be required constant) would be a simplification. I suspect most ISAs cannot sign-extend from arbitrary bit positions but only handle QI, HI and SImode though. Without SEXT_EXPR the bit-precision cases might instead argue for the shift sequence to be canonical (but generally conversions are easier to combine with, and conversions have implementation defined behavior while shifts of signed values have undefinedness issues).=