public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/114511] [11/12/13/14 Regression] Missed optimization: x = -y; x = c + x + y; ==> x=c;
Date: Fri, 05 Apr 2024 09:34:14 +0000	[thread overview]
Message-ID: <bug-114511-4-bub1VHbNfz@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-114511-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.

  _3 = _1 + _2;
  y = _3;
  _18 = b_9(D) + c_12(D);
  _19 = _18 - a_8(D);
  _20 = _3 + _19;
  _6 = _20 - _1;

re-association doesn't associate the def of _3 because it has multiple uses
and there's no special handling of

 ((_1 + _2) + _19) - _1

what makes this work for -fno-wrapv is the fre1 difference (+ is -fwrapv)

 Replaced y with _3 in all uses of y.0_4 = y;
+Matching expression match.pd:2030, gimple-match-6.cc:54
+Applying pattern match.pd:2057, gimple-match-2.cc:4362
+Applying pattern match.pd:2048, gimple-match-6.cc:2758
+gimple_simplified to _18 = b_12(D) - a_11(D);
+_5 = _18 - _1;
 Replaced x with _5 in all uses of x.1_6 = x;
-Applying pattern match.pd:4682, gimple-match-6.cc:4679
-Applying pattern match.pd:3432, gimple-match-7.cc:531
-gimple_simplified to _18 = c_16(D) - _3;
-_7 = _18;
 Replaced y with _3 in all uses of y.2_8 = y;
-Applying pattern match.pd:4682, gimple-match-7.cc:4394
-Applying pattern match.pd:3494, gimple-match-6.cc:508
-gimple_simplified to _9 = c_16(D);
 Removing dead stmt y.2_8 = y;
 Removing dead stmt x.1_6 = x;
 Removing dead stmt y.0_4 = y;
@@ -77,12 +77,12 @@
   _2 = a_11(D) - b_12(D);
   _3 = _1 + _2;
   y = _3;
-  _5 = -_3;
+  _18 = b_12(D) - a_11(D);
+  _5 = _18 - _1;
   x = _5;
-  _18 = c_16(D) - _3;
-  _7 = _18;
-  _9 = c_16(D);
-  x = c_16(D);
+  _7 = _5 + c_16(D);
+  _9 = _3 + _7;
+  x = _9;
   return;

 }

      parent reply	other threads:[~2024-04-05  9:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-28  7:24 [Bug tree-optimization/114511] New: [Regression] " 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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-114511-4-bub1VHbNfz@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).