From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 59AF4384AB43; Tue, 30 Apr 2024 06:18:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 59AF4384AB43 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714457885; bh=cKi9HWi3cAc89/AkiO+RT0X9jnrRQJ0TiNIlYpR8U54=; h=From:To:Subject:Date:From; b=ooBnZMHcH5lhfplaEPrOxYL9uQbDQokg926JKroDD9TrMrk0LfBSByeVvZwLL5PBE B9hVgjr08rnbQRUtts0BPTwyXBfQyXmzUsWTUmr5FTk0bIa+z+RwWYz/0hM5k4bZw2 tCYCBjme0KDSsFgzZ85QZFKNznjzu5mEQpYWpbRg= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114894] New: `a == 0 ? 0 : a * b` -> `a * b` likewise for `a & b` Date: Tue, 30 Apr 2024 06:18:04 +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: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: pinskia 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: bug_id short_desc product version bug_status keywords 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=3D114894 Bug ID: 114894 Summary: `a =3D=3D 0 ? 0 : a * b` -> `a * b` likewise for `a & b` Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` int fmul(int a, int b) { int c =3D a * b; int d =3D a !=3D 0; return c & -d; } int fand(int a, int b) { int c =3D a & b; int d =3D a !=3D 0; return c & -d; } ``` These should just optimize to: `return a * b;` and `return a & b;`. Currently we get: ``` c_4 =3D a_2(D) * b_3(D); _1 =3D a_2(D) !=3D 0; _6 =3D _1 ? c_4 : 0; ... c_4 =3D a_2(D) & b_3(D); _1 =3D a_2(D) !=3D 0; _6 =3D _1 ? c_4 : 0; ``` For: ``` int fmul1(int a, int b) { int c =3D a * b; if (a !=3D 0) return c; return 0; } int fand1(int a, int b) { int c =3D a & b; if (a !=3D 0) return c; return 0; } ``` It is not until phiopt4 we are able to remove the conditional.=