public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114277] New: Missed optimization: x*(x||b) => x
@ 2024-03-08  5:31 652023330028 at smail dot nju.edu.cn
  2024-03-08  6:10 ` [Bug tree-optimization/114277] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2024-03-08  5:31 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114277
           Summary: Missed optimization: x*(x||b) => x
           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
(x*(x||b) => x), but gcc -O3 missed it.

https://godbolt.org/z/W8xYrGdej

int a,b;
void func(int x){
    a=x*(x||b);
}

GCC -O3:
func(int):
        mov     eax, edi
        or      eax, DWORD PTR b[rip]
        mov     eax, 0
        cmove   edi, eax
        mov     DWORD PTR a[rip], edi
        ret

Expected code:
func(int):
        mov     DWORD PTR a[rip], edi
        ret

Surprisingly, GCC optimizes as expected for the following slightly more complex
code:
int c;
void func2(int x){
    a=x*(x||(b&&c));
}
func2(int):
        mov     DWORD PTR a[rip], edi
        ret

Thank you very much for your time and effort! We look forward to hearing from
you.

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

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

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-08  5:31 [Bug tree-optimization/114277] New: Missed optimization: x*(x||b) => x 652023330028 at smail dot nju.edu.cn
2024-03-08  6:10 ` [Bug tree-optimization/114277] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2024-03-08 10:24 ` rguenth at gcc dot gnu.org
2024-03-09  3:56 ` law at gcc dot gnu.org
2024-03-11 17:11 ` rzinsly at ventanamicro dot com
2024-03-11 17:33 ` pinskia at gcc dot gnu.org
2024-03-11 23:36 ` pinskia at gcc dot gnu.org
2024-03-12  0:45 ` pinskia 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).