From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 750243858D39; Tue, 9 Apr 2024 20:35:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 750243858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712694936; bh=zIJa4VyQ64zNdXoi9O3SH1HM5EJ05cdeHqnGV/lNEkI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=h3awlBSCpbA4C1sRIlXHFRqr6HsLW+YIWbBdZzR/LlhpKymSWwOfmohn7V4NNyPtX SaUyuC66LoIdwq+oV1PuLlS8OkgxvaVnA7RoFwJKoK5OOZSnHeUsk5WE2fNv8pwz13 QX3zmwE9n7qJMgBij0543ITOfkT2CItnbl2t+TGY= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114666] [14 Regression] Signed single bit comparison miscompile at -O2 Date: Tue, 09 Apr 2024 20:35:35 +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: 14.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: 14.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: assigned_to bug_status 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=3D114666 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot = gnu.org Status|NEW |ASSIGNED --- Comment #2 from Andrew Pinski --- Folding statement: _3 =3D _2 ^ 1; Matching expression match.pd:2835, gimple-match-2.cc:35 Matching expression match.pd:2838, gimple-match-1.cc:66 Matching expression match.pd:2845, gimple-match-2.cc:96 Matching expression match.pd:2243, gimple-match-5.cc:20 Matching expression match.pd:2835, gimple-match-2.cc:35 Matching expression match.pd:2838, gimple-match-1.cc:66 Matching expression match.pd:2845, gimple-match-2.cc:96 Applying pattern match.pd:6795, gimple-match-4.cc:1721 Matching expression match.pd:2243, gimple-match-5.cc:20 Matching expression match.pd:2286, gimple-match-3.cc:23 Matching expression match.pd:2255, gimple-match-4.cc:67 Matching expression match.pd:2243, gimple-match-5.cc:20 Applying pattern match.pd:7103, gimple-match-8.cc:47279 Applying pattern match.pd:5898, gimple-match-8.cc:47191 gimple_simplified to _7 =3D (long unsigned int) _1; _8 =3D -_7; _3 =3D _8 ^ 1; That is wrong. I can't figure out how we got there though.=20 match.pd:6795 is the pattern which does `(convert)a CMP b` into `a CMP (convert)b` which I assume VRP does `_3 =3D=3D 0 ? 1 : -2u` which then we g= et `_1 =3D=3D 0 ? 1 : -2u` (which seems reasonable) and then we apply match.pd:589= 8 which gets us to `_1 ? -2u : 1` which seems wrong as not a boolean type nor an o= ne bit unsigned integer. So the problem is with: /* !A ? B : C -> A ? C : B. */ (simplify (cnd (logical_inverted_value truth_valued_p@0) @1 @2) (cnd @0 @2 @1))) which does not check the types correctly for gimple. Note this pattern has = been there since 2014. Just been exposed the issue when I added match.pd:7103 in r14-3110-g7fb65f10285124. Let me try to figure out what to do here to fix the issue.=