From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0B93E3858D28; Tue, 20 Feb 2024 10:16:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B93E3858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708424219; bh=MwsYokeCXf20VqQOvOWdgS412T1QeQRa0ttvywrgnkQ=; h=From:To:Subject:Date:From; b=af/Ayn2GldPnly4LT2/ARWANEPf758OyFUOo1UIn2wE2G4RXdSow1/9AZhZG6EDzI xkL7f7TyG2oyDyD2pCaR3YlIpSAlelKahHJTYI/P0jPwdXiLh1Yhh8azLMLwAoUcwk xZtw3YCuYWrLzAbJuazWZDqhWfMu02ptgXAf1uRo= From: "652023330028 at smail dot nju.edu.cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114009] New: Missed optimization: (!a) * a => 0 when a=(a/2)*2 Date: Tue, 20 Feb 2024 10:16:58 +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: X-Bugzilla-Severity: normal X-Bugzilla-Who: 652023330028 at smail dot nju.edu.cn 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=3D114009 Bug ID: 114009 Summary: Missed optimization: (!a) * a =3D> 0 when a=3D(a/2)*2 Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: 652023330028 at smail dot nju.edu.cn Target Milestone: --- Hello, we noticed that the code below can be optimized as stated in the tit= le ((!a) * a =3D> 0), but gcc -O3 missed it. Different from PR 113716, this example can be optimized under the option of= gcc -O3 -fwrapv. At the same time, their patterns are different. https://godbolt.org/z/GrPY1d6o3 int w; void func(int a) { a =3D (a/2)*2; w =3D (!a) * a; } GCC -O3 : func(int): mov eax, edi xor edx, edx shr eax, 31 add eax, edi add edi, 1 sar eax cmp edi, 2 cmova eax, edx add eax, eax mov DWORD PTR w[rip], eax ret Expected code (GCC -O3 -fwrapv): func(int): mov DWORD PTR w[rip], 0 ret Thank you very much for your time and effort! We look forward to hearing fr= om you.=