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

            Bug ID: 113714
           Summary: [11/12/13/14 Regression] Missed optimization for
                    redundancy computation elimination: -(w+d-x)-x =>
                    -(w+d)
           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 x can be eliminated from the calculation of z in the
following code:
c-x => -(w+d-x)-x => -(w+d)

https://godbolt.org/z/MYhGTc4Pv

int x,y,z,w;
void func(int a, int b, int c, int d){
    x=a/b - y;
    c=-(w+d-x);
    z=c-x;
}

But GCC -O3 -fwrapv:
  _1 = a_7(D) / b_8(D);
  y.0_2 = y;
  _3 = _1 - y.0_2;
  x = _3;

  #Here is the part related to the calculation of z:
  w.2_4 = w;
  _20 = y.0_2 - w.2_4;
  _21 = _20 - d_11(D);
  _22 = _3 + _21;
  _6 = _22 - _1;
  z = _6;
  return;

Expected code:
GCC-10.5 -O3 -fwrapv
  _1 = a_7(D) / b_8(D);
  y.0_2 = y;
  _3 = _1 - y.0_2;
  x = _3;

  #Here is the part related to the calculation of z:
  w.2_4 = w;
  _5 = w.2_4 + d_11(D);
  _6 = -_5;
  z = _6;
  return;

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

Reply via email to