From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5F5EC386F424; Fri, 4 Sep 2020 12:17:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F5EC386F424 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1599221843; bh=ybiJJART61MhAlV/Nw9ntlBSWKsRkAE4CJrvzCLdVts=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pYuvzprw3CL0AXAyaOCYw+Ju73IvhMSXpQlDelXsEhR4cLil4/b27ZSAuIwDfht7g Ttf0AR2WCASTqKCvYX48TeWda+2SAgs5XMMTMuJ0SZ1xlFTd05PTgMJ9czruvwERkt 6PiEmEHs1QLlwfxeHLSWTATvbRYoxFf99xjAcigA= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/96929] Failure to optimize right shift of -1 to -1 Date: Fri, 04 Sep 2020 12:17:23 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub 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: everconfirmed bug_status cf_reconfirmed_on cc 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Sep 2020 12:17:23 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96929 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Status|UNCONFIRMED |NEW Last reconfirmed| |2020-09-04 CC| |jakub at gcc dot gnu.org --- Comment #1 from Jakub Jelinek --- We already have a rule for this: /* Optimize -1 >> x for arithmetic right shifts. */ (simplify (rshift integer_all_onesp@0 @1) (if (!TYPE_UNSIGNED (type) && tree_expr_nonnegative_p (@1)) @0)) but the rule requires that the shift count is non-negative. That was added in PR38359 fix. Even current wide_int_binop has: case RSHIFT_EXPR: case LSHIFT_EXPR: if (wi::neg_p (arg2)) { tmp =3D -arg2; if (code =3D=3D RSHIFT_EXPR) code =3D LSHIFT_EXPR; else code =3D RSHIFT_EXPR; } else tmp =3D arg2; and so it treats rshift shifts by negative values as left shifts. So, if we wanted to fix this PR, we'd need to remove the tree_expr_nonnegative_p and change wide_int_binop to perhaps best punt on negative arg2 instead of trying to handle it. Wonder what it will break.=