public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114546] New: Missed optimization: ~m || n || m+2 ==> 1
@ 2024-04-01 10:25 652023330028 at smail dot nju.edu.cn
  2024-04-01 16:47 ` [Bug tree-optimization/114546] " pinskia at gcc dot gnu.org
  2024-04-01 16:51 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2024-04-01 10:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114546
           Summary: Missed optimization: ~m || n || m+2 ==> 1
           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
(c = b || n || a ==> 1), but gcc -O3 (-fwrapv) missed it.

https://godbolt.org/z/6Kss3shKc

int a, b, c;
void test(int m, int n) {
    int t = m ^ 100;
    n = n / t;
    a = m + 2;
    b = ~m;
    c = b || n || a;
}

GCC -O3 -fwrapv:
test(int, int):
        mov     eax, esi
        lea     ecx, [rdi+2]
        mov     r8d, edi
        xor     edi, 100
        cdq
        not     r8d
        mov     DWORD PTR a[rip], ecx
        idiv    edi
        mov     DWORD PTR b[rip], r8d
        or      ecx, r8d
        mov     esi, eax
        xor     eax, eax
        or      esi, ecx
        setne   al
        mov     DWORD PTR c[rip], eax
        ret

Expected code (Clang):
test(int, int):                              # @test(int, int)
        lea     eax, [rdi + 2]
        mov     dword ptr [rip + a], eax
        not     edi
        mov     dword ptr [rip + b], edi
        mov     dword ptr [rip + c], 1
        ret

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

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

* [Bug tree-optimization/114546] Missed optimization: ~m || n || m+2 ==> 1
  2024-04-01 10:25 [Bug tree-optimization/114546] New: Missed optimization: ~m || n || m+2 ==> 1 652023330028 at smail dot nju.edu.cn
@ 2024-04-01 16:47 ` pinskia at gcc dot gnu.org
  2024-04-01 16:51 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-01 16:47 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Keywords|                            |missed-optimization

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

* [Bug tree-optimization/114546] Missed optimization: ~m || n || m+2 ==> 1
  2024-04-01 10:25 [Bug tree-optimization/114546] New: Missed optimization: ~m || n || m+2 ==> 1 652023330028 at smail dot nju.edu.cn
  2024-04-01 16:47 ` [Bug tree-optimization/114546] " pinskia at gcc dot gnu.org
@ 2024-04-01 16:51 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-01 16:51 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-04-01
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
clang/LLVM (and GCC) does not handle this either:
```
int a, b, c;
void test(int m, int n) {
    int t = m ^ 100;
    n = n / t;
    a = m + 2;
    b = ~m;
    c = (b | n | a)!=0;
}
```

Which GCC optimizes (maybe too early to) the original code to.

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

end of thread, other threads:[~2024-04-01 16:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-01 10:25 [Bug tree-optimization/114546] New: Missed optimization: ~m || n || m+2 ==> 1 652023330028 at smail dot nju.edu.cn
2024-04-01 16:47 ` [Bug tree-optimization/114546] " pinskia at gcc dot gnu.org
2024-04-01 16:51 ` 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).