public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111718] New: Missed optimization of '(a+a)/a'
@ 2023-10-07 11:05 652023330028 at smail dot nju.edu.cn
  2023-10-07 15:46 ` [Bug tree-optimization/111718] " vanyacpp at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2023-10-07 11:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111718
           Summary: Missed optimization of '(a+a)/a'
           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 found some optimizations (regarding Arithmetic optimization) that GCC
may have missed. We would greatly appreicate if you can take a look and let us
know what you think.

Given the following code: 
https://godbolt.org/z/5de17zvz9

unsigned n1,n2;
void func1(unsigned a){
    if(a>10&&a<20){
        n1=a+a;
        n2=(a+a)/a;
    }
}

We note that `(a+a)/a` should be optimized to `2`, but gcc-trunk -O3 does not:
func1(unsigned int):
        lea     eax, [rdi-11]
        cmp     eax, 8
        ja      .L1
        lea     eax, [rdi+rdi]
        xor     edx, edx
        mov     DWORD PTR n1[rip], eax
        div     edi
        mov     DWORD PTR n2[rip], eax
.L1:
        ret


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

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

end of thread, other threads:[~2023-10-08  4:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-07 11:05 [Bug tree-optimization/111718] New: Missed optimization of '(a+a)/a' 652023330028 at smail dot nju.edu.cn
2023-10-07 15:46 ` [Bug tree-optimization/111718] " vanyacpp at gmail dot com
2023-10-08  3:03 ` 652023330028 at smail dot nju.edu.cn
2023-10-08  3:52 ` pinskia at gcc dot gnu.org
2023-10-08  4:00 ` 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).