public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114511] New: [Regression] Missed optimization: x = -y; x = c + x + y; ==> x=c;
@ 2024-03-28  7:24 652023330028 at smail dot nju.edu.cn
  2024-03-28 12:49 ` [Bug tree-optimization/114511] [11/12/13/14 Regression] " xry111 at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2024-03-28  7:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114511
           Summary: [Regression] Missed optimization: x = -y; x = c + x +
                    y; ==> x=c;
           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 y can be eliminated from the calculation of x in the
following code. (x = c)

https://godbolt.org/z/716814Eh5

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

But GCC -O3 -fwrapv:
  <bb 2> [local count: 1073741824]:
  # DEBUG BEGIN_STMT
  _1 = d_7(D) / a_8(D);
  _2 = a_8(D) - b_9(D);
  _3 = _1 + _2;
  y = _3;
  # DEBUG BEGIN_STMT
  _18 = b_9(D) + c_12(D);
  _19 = _18 - a_8(D);
  # DEBUG BEGIN_STMT
  _20 = _3 + _19;
  _6 = _20 - _1;
  x = _6;
  return;

Expected code:
GCC-7.5 -O3 -fwrapv
  <bb 2> [100.00%]:
  _1 = d_7(D) / a_8(D);
  _2 = a_8(D) - b_9(D);
  _3 = _1 + _2;
  y = _3;
  x = c_12(D);
  return;

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-05  9:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-28  7:24 [Bug tree-optimization/114511] New: [Regression] Missed optimization: x = -y; x = c + x + y; ==> x=c; 652023330028 at smail dot nju.edu.cn
2024-03-28 12:49 ` [Bug tree-optimization/114511] [11/12/13/14 Regression] " xry111 at gcc dot gnu.org
2024-04-02  8:02 ` rguenth at gcc dot gnu.org
2024-04-05  2:32 ` law at gcc dot gnu.org
2024-04-05  9:34 ` rguenth at gcc dot gnu.org

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