public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hubicka at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/110377] Early VRP and IPA-PROP should work out value ranges from __builtin_unreachable
Date: Tue, 27 Jun 2023 07:45:01 +0000	[thread overview]
Message-ID: <bug-110377-4-fsle09yY4u@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110377-4@http.gcc.gnu.org/bugzilla/>

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

Jan Hubicka <hubicka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-06-27
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #5 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
OK,
I think we want to use ranger in the analysis stage then. I am testing
the following.

diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 704fe01b02c..4bc142e1471 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -2339,7 +2339,8 @@ ipa_set_jfunc_vr (ipa_jump_func *jf, value_range *tmp)

 static void
 ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
-                                    struct cgraph_edge *cs)
+                                    struct cgraph_edge *cs,
+                                    gimple_ranger *ranger)
 {
   ipa_node_params *info = ipa_node_params_sum->get (cs->caller);
   ipa_edge_args *args = ipa_edge_args_sum->get_create (cs);
@@ -2384,7 +2385,7 @@ ipa_compute_jump_functions_for_edge (struct
ipa_func_body_info *fbi,

          if (TREE_CODE (arg) == SSA_NAME
              && param_type
-             && get_range_query (cfun)->range_of_expr (vr, arg)
+             && get_range_query (cfun)->range_of_expr (vr, arg, cs->call_stmt)
              && vr.nonzero_p ())
            addr_nonzero = true;
          else if (tree_single_nonzero_warnv_p (arg, &strict_overflow))
@@ -2407,7 +2408,7 @@ ipa_compute_jump_functions_for_edge (struct
ipa_func_body_info *fbi,
                 integers and pointers.  */
              && irange::supports_p (TREE_TYPE (arg))
              && irange::supports_p (param_type)
-             && get_range_query (cfun)->range_of_expr (vr, arg)
+             && ranger->range_of_expr (vr, arg, cs->call_stmt)
              && !vr.undefined_p ())
            {
              value_range resvr = vr;
@@ -2516,7 +2517,8 @@ ipa_compute_jump_functions_for_edge (struct
ipa_func_body_info *fbi,
    from BB.  */

 static void
-ipa_compute_jump_functions_for_bb (struct ipa_func_body_info *fbi, basic_block
bb)
+ipa_compute_jump_functions_for_bb (struct ipa_func_body_info *fbi, basic_block
bb,
+                                  gimple_ranger *ranger)
 {
   struct ipa_bb_info *bi = ipa_get_bb_info (fbi, bb);
   int i;
@@ -2535,7 +2537,7 @@ ipa_compute_jump_functions_for_bb (struct
ipa_func_body_info *fbi, basic_block b
              && !gimple_call_fnspec (cs->call_stmt).known_p ())
            continue;
        }
-      ipa_compute_jump_functions_for_edge (fbi, cs);
+      ipa_compute_jump_functions_for_edge (fbi, cs, ranger);
     }
 }

@@ -3109,19 +3111,27 @@ class analysis_dom_walker : public dom_walker
 {
 public:
   analysis_dom_walker (struct ipa_func_body_info *fbi)
-    : dom_walker (CDI_DOMINATORS), m_fbi (fbi) {}
+    : dom_walker (CDI_DOMINATORS), m_fbi (fbi)
+  {
+    m_ranger = enable_ranger (cfun, false);
+  }
+  ~analysis_dom_walker ()
+  {
+    disable_ranger (cfun);
+  }

   edge before_dom_children (basic_block) final override;

 private:
   struct ipa_func_body_info *m_fbi;
+  gimple_ranger *m_ranger;
 };

 edge
 analysis_dom_walker::before_dom_children (basic_block bb)
 {
   ipa_analyze_params_uses_in_bb (m_fbi, bb);
-  ipa_compute_jump_functions_for_bb (m_fbi, bb);
+  ipa_compute_jump_functions_for_bb (m_fbi, bb, m_ranger);
   return NULL;
 }

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr110377.c
b/gcc/testsuite/gcc.dg/tree-ssa/pr110377.c
new file mode 100644
index 00000000000..d770f8babba
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr110377.c
@@ -0,0 +1,17 @@
+/* { dg-do compile */
+/* { dg-options "-O2 -fdump-ipa-fnsummary" } */
+int test3(int);
+__attribute__ ((noinline))
+void test2(int a)
+{
+       test3(a);
+}
+void
+test(int n)
+{
+        if (n > 5)
+          __builtin_unreachable ();
+        test2(n);
+}
+/* { dg-final { scan-tree-dump "-INF, 5-INF" "fnsummary" } }  */

  parent reply	other threads:[~2023-06-27  7:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-23 15:37 [Bug middle-end/110377] New: Early VRP and IPA-PROP should work out value ranges from __builtin_unreacahble hubicka at gcc dot gnu.org
2023-06-26  8:56 ` [Bug middle-end/110377] Early VRP and IPA-PROP should work out value ranges from __builtin_unreachable rguenth at gcc dot gnu.org
2023-06-26 14:20 ` amacleod at redhat dot com
2023-06-26 16:48 ` hubicka at gcc dot gnu.org
2023-06-26 19:49 ` amacleod at redhat dot com
2023-06-27  7:45 ` hubicka at gcc dot gnu.org [this message]
2023-06-28  7:35 ` cvs-commit at gcc dot gnu.org
2023-11-21 15:12 ` hubicka at gcc dot gnu.org

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-110377-4-fsle09yY4u@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).