public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114651] New: Missed optimization: (c - y) + ((a - c) - (b - y)) => a-b
@ 2024-04-09  6:13 652023330028 at smail dot nju.edu.cn
  0 siblings, 0 replies; only message in thread
From: 652023330028 at smail dot nju.edu.cn @ 2024-04-09  6:13 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114651
           Summary: Missed optimization: (c - y) + ((a - c) - (b - y)) =>
                    a-b
           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 the computation of 'z' in the following code can be
optimized to 'a-b'.

https://godbolt.org/z/hKT8YT6MW

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

But GCC -O3 (-fwrapv):
  _1 = a_10(D) / b_8(D);
  _2 = _1 + c_11(D);
  y = _2;
  # DEBUG BEGIN_STMT
  _4 = a_10(D) - c_11(D);
  _17 = _4 - b_8(D);
  _6 = _2 + _17;
  _3 = _6 - _1;
  z = _3;


Expected code:
  _1 = a_7(D) / b_8(D);
  _2 = _1 + c_9(D);
  y = _2;
  # DEBUG BEGIN_STMT
  _17 = a_7(D) - b_8(D);
  z = _17;

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-09  6:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-09  6:13 [Bug tree-optimization/114651] New: Missed optimization: (c - y) + ((a - c) - (b - y)) => a-b 652023330028 at smail dot nju.edu.cn

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).