public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Andrew Macleod <amacleod@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-5628] Always track arguments, even when ignoring equiv params.
Date: Tue, 30 Nov 2021 14:10:21 +0000 (GMT)	[thread overview]
Message-ID: <20211130141021.1F43F385AC3B@sourceware.org> (raw)

https://gcc.gnu.org/g:e43b15c88c242b14a8ced8e631c1f9b80e83d63c

commit r12-5628-ge43b15c88c242b14a8ced8e631c1f9b80e83d63c
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Mon Nov 29 09:19:34 2021 -0500

    Always track arguments, even when ignoring equiv params.
    
    To "ignore" ranges from equivalences, we should track the range separately,
    but still do the other name processing which determiens if there is a single
    name or not for equivalence.  Otherwise we mistakently think we can introduce
    an equivalences.
    
            gcc/
            PR tree-optimization/103440
            * gimple-range-fold.cc (fold_using_range::range_of_phi): Continue
            normal param processing for equiv params.
    
            gcc/testsuite/
            * gcc.dg/pr103440.c: New.

Diff:
---
 gcc/gimple-range-fold.cc        | 21 +++++++++------------
 gcc/testsuite/gcc.dg/pr103440.c | 24 ++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc
index d66ada5bb7c..58122297c0b 100644
--- a/gcc/gimple-range-fold.cc
+++ b/gcc/gimple-range-fold.cc
@@ -795,20 +795,17 @@ fold_using_range::range_of_phi (irange &r, gphi *phi, fur_source &src)
       // Get the range of the argument on its edge.
       src.get_phi_operand (arg_range, arg, e);
 
-      // Likewise, if the incoming PHI argument is equivalent to this
-      // PHI definition, it provides no new info.  Accumulate these ranges
-      // in case all arguments are equivalences.
-      if (src.query ()->query_relation (e, arg, phi_def, false) == EQ_EXPR)
-	{
-	  single_arg = arg;
-	  equiv_range.union_(arg_range);
-	  continue;
-	}
-
       if (!arg_range.undefined_p ())
 	{
 	  // Register potential dependencies for stale value tracking.
-	  r.union_ (arg_range);
+	  // Likewise, if the incoming PHI argument is equivalent to this
+	  // PHI definition, it provides no new info.  Accumulate these ranges
+	  // in case all arguments are equivalences.
+	  if (src.query ()->query_relation (e, arg, phi_def, false) == EQ_EXPR)
+	    equiv_range.union_(arg_range);
+	  else
+	    r.union_ (arg_range);
+
 	  if (gimple_range_ssa_p (arg) && src.gori ())
 	    src.gori ()->register_dependency (phi_def, arg);
 
@@ -829,7 +826,7 @@ fold_using_range::range_of_phi (irange &r, gphi *phi, fur_source &src)
 
     // If all arguments were equivalences, use the equivalence ranges as no
     // arguments were processed.
-    if (!seen_arg)
+    if (r.undefined_p () && !equiv_range.undefined_p ())
       r = equiv_range;
 
     // If the PHI boils down to a single effective argument, look at it.
diff --git a/gcc/testsuite/gcc.dg/pr103440.c b/gcc/testsuite/gcc.dg/pr103440.c
new file mode 100644
index 00000000000..b97f45cd3ed
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr103440.c
@@ -0,0 +1,24 @@
+/* { dg-do run } */
+/* { dg-options "-Os" } */
+/* { dg-timeout 10 } */
+
+int a, b, c, d, e;
+int main() {
+  int f = 2, g = 1, h = -3;
+L1:
+  c = b ^ 1;
+  if (!f)
+    goto L3;
+  if (d)
+    g = e;
+  f = h;
+  if (!c)
+    goto L1;
+L2:
+  if (g)
+    a = 0;
+L3:
+  if (d == g)
+    goto L2;
+  return 0;
+}


                 reply	other threads:[~2021-11-30 14:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20211130141021.1F43F385AC3B@sourceware.org \
    --to=amacleod@gcc.gnu.org \
    --cc=gcc-cvs@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).