From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8D5973858D1E; Sun, 19 May 2024 22:57:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D5973858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1716159471; bh=1e9Zm0Pe0TvYWW8DMe9sYictHgS5YX6yIcnbkQfM31M=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rSsRRSSMtPh4yfDZpKe8blVnc09Er+sBNFr/SYdQd9V66u//W3UIOXaj90p8dGnNT h7Yx1HW3Lhxsm6YRMOHn2vSmrj48wJYg9CTGFqIA30cMQ4QvHJD07IltUE2mJAAK3P /ho8Xu+FndXFUHgy8gU0HiiI9VQcGCDhTTig2Bjw= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/115154] [13/14/15 Regression] wrong code at optimization levels -O2, -O3, -Os since r13-7434-g682bbd364708fe Date: Sun, 19 May 2024 22:57:51 +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: 13.2.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: pinskia at gcc dot gnu.org X-Bugzilla-Target-Milestone: 13.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cf_known_to_work short_desc 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=3D115154 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Known to work|14.1.0 | Summary|[13 Regression] wrong code |[13/14/15 Regression] wrong |at optimization levels -O2, |code at optimization levels |-O3, -Os since |-O2, -O3, -Os since |r13-7434-g682bbd364708fe |r13-7434-g682bbd364708fe --- Comment #10 from Andrew Pinski --- This works and might be the best for GCC 13/14 but maybe I think we can do better. ``` diff --git a/gcc/match.pd b/gcc/match.pd index 0f9c34fa897..6bc512cabdf 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2400,7 +2400,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (convert (mult@0 zero_one_valued_p@1 INTEGER_CST@2)) (if (INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (TREE_TYPE (@0)) - && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@0))) + && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@0)) + && (TYPE_UNSIGNED (type) || TYPE_PRECISION (type) > 1)) (mult (convert @1) (convert @2)))) /* (X << C) !=3D 0 can be simplified to X, when C is zero_one_valued_p. ``` For bit 1 precision, look at the lower bit of the INTEGER_CST and decide if= it should be @1 or `0` and that would avoid the overflow too. Note you can reproduce the failure on the trunk and GCC 14 by using -fsanitize=3Dundefined which I missed in the original bug report and that is because r14-3432-gddd64a6ec3b38e is disable for undefined sanitizers case.=