From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 318F53858CDB; Tue, 10 Oct 2023 19:25:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 318F53858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696965923; bh=HCezlWILrak4iLeSDhOvspvgBHMG+NUt7BhIyVdK5aE=; h=From:To:Subject:Date:From; b=lV7UsPokrXtz3k9PqVCZMErAZ73RXYZ72PjOuOxwJ064TLz0nEqdu78gcgoCJsTCa t+l5gijH+jENlWxY1vD8ke8eoBDhHKH5l3cYJhZxEWqNG8gDwIXSCfnwFRTsgdjfI7 STbdZcyKmeL6jqARypxEShOWiiC/GoZ8nKlMbQhE= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/111762] New: `(a | 3) ^ 1` and `(a & ~1) | 2` should produce the same code Date: Tue, 10 Oct 2023 19:25:22 +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: internal-improvement 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=3D111762 Bug ID: 111762 Summary: `(a | 3) ^ 1` and `(a & ~1) | 2` should produce the same code Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: internal-improvement 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 f(int in) { in =3D in | 3; in =3D in ^ 1; return in; } int f1(int in) { in =3D (in & ~(unsigned long)1); in =3D in | 2; return in; } ``` These 2 functions produce the same result but the code generated is differe= nt. I noticed this while writing the patch for PR 111282 and noticing that `gcc.dg/tree-ssa/and-1.c` testcase now fails (test needs to be fixed). LLVM/clang looks like canonicalizes to f1. I suspect xor is harder to optim= ize when dealing with reassociation so doing f1 is better.=