From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6F6343858C29; Wed, 31 Jan 2024 13:44:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F6343858C29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706708659; bh=FPbdPgunmfIdzPQ+j709ZJAehTksDbqmCxdPhrZvIcc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=cqNhxFANm9kp0ABFvE1qvAVkwX4G/BlIQJ9QvBt6/tzCG7S2IE9L3iIwa1h3S47vC Fb9pHzgOp6T0eIn9l5XMcb4Nb6w+XREOVzExRv0yX1QRtjmYuAiqSe875O5zObWHQy +bWmsjdfc/c2ngwJo3lzeL6RveM7Y+RRgdlWqusQ= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/110176] [11/12/13/14 Regression] wrong code at -Os and above on x86_64-linux-gnu since r11-2446 Date: Wed, 31 Jan 2024 13:44:16 +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.1.1 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.5 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=3D110176 --- Comment #9 from Richard Biener --- With all VARYING we simplify i_19 =3D (int) _2; _6 =3D (int) _5; Value numbering stmt =3D _7 =3D _6 <=3D i_19; Applying pattern match.pd:6775, gimple-match-4.cc:1795 Match-and-simplified _6 <=3D i_19 to 1 where _5 is _Bool and _2 is unsigned int. We match zext <=3D (int) 4294967295u note that I see Value numbering stmt =3D _2 =3D f$0_25; Setting value number of _2 to 4294967295 (changed) Value numbering stmt =3D i_19 =3D (int) _2; Match-and-simplified (int) _2 to -1 RHS (int) _2 simplified to -1=20 Not changing value number of i_19 from VARYING to -1 Making available beyond BB6 i_19 for value i_19 so it's odd we see the constant here, but ... we go (if (TREE_CODE (@10) =3D=3D INTEGER_CST && INTEGRAL_TYPE_P (TREE_TYPE (@00)) && !int_fits_type_p (@10, TREE_TYPE (@00))) (with { tree min =3D lower_bound_in_type (TREE_TYPE (@10), TREE_TYPE (@00= )); tree max =3D upper_bound_in_type (TREE_TYPE (@10), TREE_TYPE (@00= )); bool above =3D integer_nonzerop (const_binop (LT_EXPR, type, max, @10)); bool below =3D integer_nonzerop (const_binop (LT_EXPR, type, @10, min)); } (if (above || below) failing to see that we deal with a relational compare and a sign-change. The original code from fold-const.cc had only INTEGER_TYPE support, r6-4300-gf6c1575958f7bf made it cover all integral types (it half-way supported BOOLEAN_TYPE already). But the issue was latent I think. One notable difference was that I think get_unwidened made sure to convert a constant to the wider type while here we have @10 !=3D @1 and the conversion not applied. We're doing it correct in earlier code: /* ??? The special-casing of INTEGER_CST conversion was in the original code and here to avoid a spurious overflow flag on the resulting constant which fold_convert produces. */ (if (TREE_CODE (@1) =3D=3D INTEGER_CST) using @1 instead of @10. Correcting that avoids the pattern from triggering in this wrong way.=