From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EE5C83858CDB; Tue, 10 Oct 2023 19:32:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE5C83858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696966357; bh=I1uS5RszVjF0e7OyZLwBVBvs+NY7FF1Qun0nOGA6mj4=; h=From:To:Subject:Date:From; b=tP+2GQBIlbQkcIcqPI+vpiiRFfQAJIyP6w4HYgTuH6Cnzwn07fFM0BIfgtwljuq2u nYejMjOlWa19rS0zjiUYHmwBGdvfkamklkTlsAYaVdBFgdTC555EFV1RYj1GBiuKuV 6PdX3WIx5DNg2iVqrrFpl5tkL/XF6+KaDlyNaWVo= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/111763] New: `(a & ~1) | 2` could be done as `(a & ~(1 | 2)) + 2` which allows to use leal Date: Tue, 10 Oct 2023 19:32:37 +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: 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 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=3D111763 Bug ID: 111763 Summary: `(a & ~1) | 2` could be done as `(a & ~(1 | 2)) + 2` which allows to use leal Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Target: x86_64-linux-gnu Take: ``` int f1(int in) { in =3D (in & ~(unsigned long)1); in =3D in | 2; return in; } int f2(int in) { in =3D (in & ~(unsigned long)(1|2)); in =3D in + 2; return in; } ``` We currently get: ``` f1: movl %edi, %eax andl $-2, %eax orl $2, %eax ret f2: andl $-4, %edi leal 2(%rdi), %eax ret ``` The leal version is better because it saves more move due to leal not being= a 2 operand but 3 operand instruction so it could improve register allocation .= .. I noticed this whole looking into PR 111762 (and PR 111282) and looking at clang/LLVM's code generation here . Also I don't know how often this shows up though.=