From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1DC1D3858C66; Mon, 6 Mar 2023 18:19:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1DC1D3858C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678126740; bh=TbEFGgS1QR/AU8ZleoLosGkRU4HtQi/jW9ipgia6Ksk=; h=From:To:Subject:Date:From; b=wJo6qCzsU/T8gl9DTsez3uMdpPiM+AFWmP9iOL9om19Cyjg+oU8Aqb1uIwpf+W6nh 7SdLxDWo2YTmPa0z4z81Ho6rR2/DvGAKG0S13UDxtCX8ei7QTus/yTq/loFA5M2gcH 0j+ttE2n6w+P3hyrKIlXUSG/9MLip/AhyH981/Ms= From: "llvm at rifkin dot dev" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109044] New: Missed fold for (n - 1) / 2 when n is odd Date: Mon, 06 Mar 2023 18:18:59 +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: 12.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: llvm at rifkin dot dev 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=3D109044 Bug ID: 109044 Summary: Missed fold for (n - 1) / 2 when n is odd Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: llvm at rifkin dot dev Target Milestone: --- int foo(unsigned n) { if(n % 2 =3D=3D 0) __builtin_unreachable(); return (n - 1) / 2; } int bar(unsigned n) { return n >> 1; } foo(unsigned int): lea eax, [rdi-1] shr eax ret bar(unsigned int): mov eax, edi shr eax ret https://godbolt.org/z/3G7enYdnM https://alive2.llvm.org/ce/z/m3qbdN=