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.

Reply via email to