From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EA6A53858CDB; Thu, 18 May 2023 20:35:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA6A53858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684442134; bh=ECT3FpLpSGIx3CjuRPSLm9TV0fV4uFSu85YZoIzu0X4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Hhd4qFWmJsANIla6W/Jaz0geG0WXYlpM7OccxBYT+/I1IGeSJw7Ne3H9s8sOz+qTM H1L23X/m0VnIY6iiRyxpZ5BAA/3Im095ZFf88VBVMC+iuOcf2I/J+Eqy0mTQnuhcyB qhAba1abzwZI1aHXj1+BMNRlwWRuN+T/ZUwIYJBo= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/101807] bool0 < bool1 Should expand as !bool0 &bool1 and bool0 <= bool1 as !bool0 | bool1 Date: Thu, 18 May 2023 20:35:34 +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: 12.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement 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: --- 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=3D101807 --- Comment #4 from Andrew Pinski --- Here is what I have so far without the cost model: /* Hand bool0 CMP bool1 because bitwise operators are normally better than comparisons. */ if (INTEGRAL_TYPE_P (type) && ((tree_nonzero_bits (arg0) =3D=3D 1 && tree_nonzero_bits (arg1) = =3D=3D 1) || (unsignedp && TYPE_PRECISION (type) =3D=3D 1))) { tree b0 =3D arg0; tree b1 =3D arg1; bool not_p =3D false; bool operand1_not_p =3D false; tree_code code =3D ERROR_MARK; switch (ops->code) { case EQ_EXPR: not_p =3D true; code =3D BIT_XOR_EXPR; break; case NE_EXPR: code =3D BIT_XOR_EXPR; break; case GT_EXPR: std::swap (b0, b1); code =3D BIT_AND_EXPR; operand1_not_p =3D true; break; case LT_EXPR: code =3D BIT_AND_EXPR; operand1_not_p =3D true; break; case GE_EXPR: std::swap (b0, b1); code =3D BIT_IOR_EXPR; operand1_not_p =3D true; break; case LE_EXPR: code =3D BIT_IOR_EXPR; operand1_not_p =3D true; break; default: code =3D ERROR_MARK; break; } if (code !=3D ERROR_MARK) { tree exp; tree one =3D build_int_cst (type, 1); if (operand1_not_p) b0 =3D build2_loc (loc, BIT_XOR_EXPR, type, b0, one); exp =3D build2_loc (loc, code, type, b0, b1); if (not_p) exp =3D build2_loc (loc, BIT_XOR_EXPR, type, exp, one); return expand_expr (exp, target, VOIDmode, EXPAND_NORMAL); } }=