public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114009] New: Missed optimization: (!a) * a => 0 when a=(a/2)*2
@ 2024-02-20 10:16 652023330028 at smail dot nju.edu.cn
  2024-02-20 23:50 ` [Bug tree-optimization/114009] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2024-02-20 10:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114009

            Bug ID: 114009
           Summary: Missed optimization: (!a) * a => 0 when a=(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 title
((!a) * a => 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 = (a/2)*2;
    w = (!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 from
you.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-03-15  9:45 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-20 10:16 [Bug tree-optimization/114009] New: Missed optimization: (!a) * a => 0 when a=(a/2)*2 652023330028 at smail dot nju.edu.cn
2024-02-20 23:50 ` [Bug tree-optimization/114009] " pinskia at gcc dot gnu.org
2024-02-20 23:56 ` [Bug tree-optimization/114009] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2024-02-21  0:03 ` pinskia at gcc dot gnu.org
2024-02-22 10:21 ` rguenth at gcc dot gnu.org
2024-03-05 13:02 ` jakub at gcc dot gnu.org
2024-03-05 14:14 ` jakub at gcc dot gnu.org
2024-03-05 14:24 ` jakub at gcc dot gnu.org
2024-03-07  7:47 ` cvs-commit at gcc dot gnu.org
2024-03-15  9:45 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).