From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F00AF3857C69; Wed, 13 Mar 2024 14:19:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F00AF3857C69 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710339559; bh=+7ii0Cro9cljLOfXS/kDkmo+irDjPmWP4isoNLgFCcg=; h=From:To:Subject:Date:From; b=Vb/r//HNTggptbkGWtu7IRZ2bqmqWgRRS9k3uBk3/pVqnUeOcIeSvbW1dXX5dlpuO 0R06njqlRZODuGT7Fq4HIYuGf5eH1LeKmX9qW2aXx6qMdd6ljR29vB28Q9GMBSL4jJ zjexJnBgKMLV8MwGsaRZnYdBEe9k0EogdH7DK9CI= From: "manolis.tsamis at vrull dot eu" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114326] New: Missed optimization for A || B when !B implies A. Date: Wed, 13 Mar 2024 14:19:19 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: manolis.tsamis at vrull dot eu 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D114326 Bug ID: 114326 Summary: Missed optimization for A || B when !B implies A. Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: manolis.tsamis at vrull dot eu Target Milestone: --- The function below doesn't fold to return 0; int cmp1(uint64_t d1, uint64_t d2) { if (((d1 ^ d2) & 0xabcd) =3D=3D 0 || d1 !=3D d2) return 0; return foo(); } while the following function does:=20 int cmp2(uint64_t d1, uint64_t d2) { if (d1 !=3D d2 || ((d1 ^ d2) & 0xabcd) =3D=3D 0) return 0; return foo(); } The functions are equivalent since the lhs and rhs of || don't have side effects. In general, there pattern here is a side-effect free expression a || b wher= e !b implies a should be optimized to true. As in the testcase above, a doesn't necessarily imply !b. Something similar could be stated for && expressions. Complementary godbolt link: https://godbolt.org/z/qK5bYf36T=