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

            Bug ID: 112994
           Summary: [Regression] Missed optimization for redundancy
                    computation elimination because pattern is broken
           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 maybe there is a missed optimization for redundancy
computation elimination.

Different from PR 111718, this missed optimization is a regression and not just
because of one missing pattern, but because of changes that broke patterns that
could have been eliminated:

The pattern /* Simplify (t * 2) / t) -> 2.  */ is broken.

https://godbolt.org/z/3er613Krx
int n,m;
void test(int a, int b){

    n=a+a;
    b=n;
    m=(n+b)/(b);
}

GCC (trunk) -O3:
test(int, int):
        lea     eax, [0+rdi*4]
        lea     ecx, [rdi+rdi]
        cdq
        mov     DWORD PTR n[rip], ecx
        idiv    ecx
        mov     DWORD PTR m[rip], eax
        ret

Expected code (GCC 11.4 -O3):
test(int, int):
        mov     DWORD PTR m[rip], 2
        add     edi, edi
        mov     DWORD PTR n[rip], edi
        ret

If our targeting is accurate, then this issue was caused by this commit:
https://github.com/gcc-mirror/gcc/commit/d846f225c25

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

Reply via email to