From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D2C1A38582A1; Thu, 21 Jul 2022 09:48:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D2C1A38582A1 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/106379] DCE depends on order Date: Thu, 21 Jul 2022 09:48:52 +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: 12.1.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED 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: keywords everconfirmed bug_status cf_reconfirmed_on cc component 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: Thu, 21 Jul 2022 09:48:52 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106379 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |missed-optimization Ever confirmed|0 |1 Status|UNCONFIRMED |ASSIGNED Last reconfirmed| |2022-07-21 CC| |amacleod at redhat dot com Component|c |tree-optimization --- Comment #1 from Richard Biener --- Confirmed. We don't recognize the pattern in GENERIC folding, instead for = the good case VRP1 handles _Bool _1; _Bool _2; [local count: 1073741824]: _1 =3D ~c_4(D); if (c_4(D) !=3D s_5(D)) goto ; [66.00%] else goto ; [34.00%] [local count: 365072224]: _2 =3D _1 & s_5(D); if (_2 !=3D 0) goto ; [33.00%] else goto ; [67.00%] [local count: 120473833]: DCEMarker0_ (); [local count: 1073741824]: return; well while not handling _Bool _1; _Bool _2; [local count: 1073741824]: if (s_4(D) !=3D c_5(D)) goto ; [66.00%] else goto ; [34.00%] [local count: 365072224]: _1 =3D ~c_5(D); _2 =3D _1 & s_4(D); if (_2 !=3D 0) goto ; [33.00%] else goto ; [67.00%] [local count: 120473833]: DCEMarker0_ (); [local count: 1073741824]: return; we are probably very early defeating equivalence handling by folding !a =3D=3D !b to !a ^ b (and which one gets the inversion depends on the ord= er which is the underlying issue this PR points out). It's also apparent that we fail to simplify !a =3D=3D !b to a =3D=3D b for = boolean a, b. We arrive there via fold_binary_loc's /* ARG0 is the first operand of EXPR, and ARG1 is the second operand. First check for cases where an arithmetic operation is applied to a compound, conditional, or comparison operation. Push the arithmetic operation inside the compound or conditional to see if any folding can then be done. Convert comparison to conditional for this purpose. The also optimizes non-constant cases that used to be done in expand_expr. Before we do that, see if this is a BIT_AND_EXPR or a BIT_IOR_EXPR, one of the operands is a comparison and the other is a comparison, a BIT_AND_EXPR with the constant 1, or a truth value. In that case, the code below would make the expression more complex. Change it to a TRUTH_{AND,OR}_EXPR. Likewise, convert a similar NE_EXPR to TRUTH_XOR_EXPR and an EQ_EXPR to the inversion of a TRUTH_XOR_EXPR. */ which generates !a ^ !b which is eventually inverted to !a ^ b. Adding (simplify (bit_not (bit_xor truth_valued_p@0 truth_valued_p@1)) (eq @0 @1)) fixes this but code generation of _Bool foo (_Bool a, _Bool b) { return !a =3D=3D !b; } changes from xorl %edi, %esi movl %esi, %eax xorl $1, %eax ret to cmpb %sil, %dil sete %al=