From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E8F753858410; Mon, 25 Mar 2024 07:23:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8F753858410 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1711351389; bh=MM1JPWb50sIEWAznFE+D/OJZ28EjH+ao16NwABosyV4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=OD4PM3L414EeBMjnwAF1uw9YXOUtOYpQ/WbIjgMfZMcd/bnQipGdUs1nB1WqW3r1O PJV/tL1wxb88Dswc3ZWl55BI+TpHL+8rt1EzcJJrJhZIEqi4hf1j+wfkX/f7bm1gZc V/TbyEXPkY4NeA4AgKw5QboL5MeyQgn9pWljmZ/o= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/111151] [12/13/14 Regression] Wrong code at -O0 on x86_64-pc-linux-gnu Date: Mon, 25 Mar 2024 07:23:07 +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: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.4 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=3D111151 --- Comment #13 from Richard Biener --- (In reply to Jakub Jelinek from comment #11) > Perhaps > --- fold-const.cc.jj8 2024-03-11 22:37:29.000000000 +0100 > +++ fold-const.cc 2024-03-22 19:31:44.189686120 +0100 > @@ -7104,6 +7104,27 @@ extract_muldiv_1 (tree t, tree c, enum t > if (TYPE_UNSIGNED (ctype) !=3D TYPE_UNSIGNED (type)) > break; >=20=20 > + /* Punt for multiplication altogether. > + MAX (1U + INT_MAX, 1U) * 2U is not equivalent to > + MAX ((1U + INT_MAX) * 2U, 1U * 2U), the former is > + 0U, the latter is 2U. > + MAX (INT_MIN / 2, 0) * -2 is not equivalent to > + MIN (INT_MIN / 2 * -2, 0 * -2), the former is > + well defined 0, the latter invokes UB. > + MAX (INT_MIN / 2, 5) * 5 is not equivalent to > + MAX (INT_MIN / 2 * 5, 5 * 5), the former is > + well defined 25, the latter invokes UB. */ > + if (code =3D=3D MULT_EXPR) > + break; > + /* For division/modulo, punt on c being -1 for MAX, as > + MAX (INT_MIN, 0) / -1 is not equivalent to > + MIN (INT_MIN / -1, 0 / -1), the former is well defined > + 0, the latter invokes UB (or for -fwrapv is INT_MIN). > + MIN (INT_MIN, 0) / -1 already invokes UB, so the > + transformation won't make it worse. */ > + else if (tcode =3D=3D MAX_EXPR && integer_minus_onep (c)) > + break; > + > /* MIN (a, b) / 5 -> MIN (a / 5, b / 5) */ > sub_strict_overflow_p =3D false; > if ((t1 =3D extract_muldiv (op0, c, code, wide_type, > ? I think that looks reasonable.=