From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EFC5B3858D37; Thu, 27 Apr 2023 22:47:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EFC5B3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682635635; bh=hDQziYhPg5J7G5fHeOJKcWIKS2bh5zguKECX4d0wgs0=; h=From:To:Subject:Date:From; b=b0s5jLqRWT+Ei4ZkzwK6WpQCErymUB+vcu8Qd71wEc5xQdxCYS36gUtBU/sx1HHLA Nne0d18Ak1PcKa8RnHYm06bsLPBP/fBqfhomZ459yDtNE9MR6zZ5rm/ze5esc5x3IK NNaSqC5i5PgbwBuYYmVs0ipf0V9WmOQHiCD8Lax4= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/109657] New: (a ? -1 : 0) | b could be optimized better for aarch64 Date: Thu, 27 Apr 2023 22:47:15 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 13.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: pinskia 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 cf_gcctarget 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=3D109657 Bug ID: 109657 Summary: (a ? -1 : 0) | b could be optimized better for aarch64 Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: target Assignee: pinskia at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Target: aarch64-*-* Take (at -O2): ``` unsigned b(unsigned a, unsigned b){ if(b){ return -1; } return a; } unsigned b1(unsigned a, unsigned b){ unsigned t =3D b ? -1 : 0; return a | t; } ``` Right now we produce: ``` b: cmp w1, 0 csinv w0, w0, wzr, eq ret b1: cmp w1, 0 csetm w1, ne orr w0, w1, w0 ret ``` We can help combine here by adding a pattern for: (set (reg/i:SI 0 x0) (ior:SI (neg:SI (ne:SI (reg:CC 66 cc) (const_int 0 [0]))) (reg:SI 102))) Which is the same as=20 (set (reg/i:SI 0 x0) (if_then_else:SI (eq (reg:CC 66 cc) (const_int 0 [0])) (reg:SI 97) (const_int -1 [0xffffffffffffffff]))) pattern. I suspect both are considered canonical too.=