From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 473663858C54; Mon, 27 Feb 2023 17:11:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 473663858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677517908; bh=3keBmmLUnQi4Rt4XBtAwYS5COEVm1h23ixsPvdqE4RM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=wYQHAa49okK/JxFWkIDhAeeyeKPO/vCULWstoLCtY/D4kGpsVgbISH8qD/wqWjY68 yYjcaw7Dcki+5yMxFiAxpbkiyF3j8WXhFm82+wqK03sOwiUjpiJufk27O6nMocmLy7 SYkT5vUvomqXRbW7vLu1ryxXT+qJ8yK+Z16gHkYY= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/108953] inefficient codegen for trivial equality Date: Mon, 27 Feb 2023 17:11:47 +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.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED 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: component cc 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=3D108953 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- Component|c++ |tree-optimization CC| |jakub at gcc dot gnu.org --- Comment #1 from Jakub Jelinek --- I don't think there is anything the C++ FE should do here, user can write it like that by hand too: bool check(C const& lhs, C const& rhs) { if (lhs.a !=3D rhs.a) return false; if (lhs.b !=3D rhs.b) return false; if (lhs.c !=3D rhs.c) return false; if (lhs.d !=3D rhs.d) return false; if (lhs.e !=3D rhs.e) return false; if (lhs.f !=3D rhs.f) return false; if (lhs.g !=3D rhs.g) return false; return true; } etc., so we should pattern match this somewhere during GIMPLE opts. The memcmp issue is a RTL issue (so I think we want actually two bugs), at GIMPLE level it is optimized into: _1 =3D __builtin_memcmp_eq (lhs_3(D), rhs_4(D), 12); _5 =3D _1 =3D=3D 0; return _5; which is I think what we want. The reason for doing conditional branch after each comparison is targetm.compare_by_pieces_branch_ratio (DImode) tells it not to batch more = than one. Not really sure if we should override it to something else and on which targets. The reason for the weird mov eax, 1 test eax, eax sete al instead of xor eax, eax and xor eax, eax test eax, eax sete al instead of mov eax, 1 is that the epilogue is threaded only too late where the constant propagati= on through it isn't possible.=