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

            Bug ID: 114545
           Summary: [11/12/13/14 Regression] Missed optimization for CSE
           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 there may be a missed CSE (t+c). Here is the reduced
code:

https://godbolt.org/z/f68qWa89s

int a, b, c;
void func() {
  int t=0;
  t = -a;
  b = -(t + c);
  a = t + c;
}

GCC -O3 -fwrapv:
func():
        mov     edx, DWORD PTR a[rip]
        mov     eax, DWORD PTR c[rip]
        mov     ecx, edx
        sub     ecx, eax
        sub     eax, edx
        mov     DWORD PTR b[rip], ecx
        mov     DWORD PTR a[rip], eax
        ret

Expected code:
GCC-7.5: 
func():
        mov     eax, DWORD PTR c[rip]
        sub     eax, DWORD PTR a[rip]
        mov     edx, eax
        mov     DWORD PTR a[rip], eax
        neg     edx
        mov     DWORD PTR b[rip], edx
        ret

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

Reply via email to