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-5006] Don't calculate new values when using the private context callback.
Date: Mon,  8 Nov 2021 17:49:13 +0000 (GMT)	[thread overview]
Message-ID: <20211108174913.C5E923858D3C@sourceware.org> (raw)

https://gcc.gnu.org/g:0cd653bd2559701da9cc4c9bf51f22bdd68623b5

commit r12-5006-g0cd653bd2559701da9cc4c9bf51f22bdd68623b5
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Mon Nov 8 09:32:42 2021 -0500

    Don't calculate new values when using the private context callback.
    
    When using rangers private callback mechanism to provide context
    to fold_stmt calls, we are only suppose to be using the cache in read
    only mode, never calculate new values.
    
            gcc/
            PR tree-optimization/103122
            * gimple-range.cc (gimple_ranger::range_of_expr): Request the cache
            entry with "calulate new values" set to false.
    
            gcc/testsuite/
            * g++.dg/pr103122.C: New.

Diff:
---
 gcc/gimple-range.cc             |  4 ++--
 gcc/testsuite/g++.dg/pr103122.C | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index e1177b1c5e8..87dba6e81d8 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -88,8 +88,8 @@ gimple_ranger::range_of_expr (irange &r, tree expr, gimple *stmt)
       if (!m_cache.get_global_range (r, expr))
         r = gimple_range_global (expr);
       // Pick up implied context information from the on-entry cache
-      // if current_bb is set.
-      if (current_bb && m_cache.block_range (tmp, current_bb, expr))
+      // if current_bb is set.  Do not attempt any new calculations.
+      if (current_bb && m_cache.block_range (tmp, current_bb, expr, false))
 	{
 	  r.intersect (tmp);
 	  char str[80];
diff --git a/gcc/testsuite/g++.dg/pr103122.C b/gcc/testsuite/g++.dg/pr103122.C
new file mode 100644
index 00000000000..3465eade46b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr103122.C
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+unsigned a;
+int b;
+short c;
+void d(long) {
+  for (bool e = (bool)c - 1; e < (bool)b - 1; e += 0)
+    ;
+  if (a) {
+    for (char f = 0; f < 7; f = 7)
+      for (int g = 0; g < c; g += 10)
+        ;
+    d(-!c);
+  }
+}


                 reply	other threads:[~2021-11-08 17:49 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=20211108174913.C5E923858D3C@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).