diff mbox series

[COMMITTED] tree-optimization/102796 - Process EH edges again.

Message ID 803718e3-dd35-0c6b-05f5-96af9897bf02@redhat.com
State New
Headers show
Series [COMMITTED] tree-optimization/102796 - Process EH edges again. | expand

Commit Message

Andrew MacLeod Oct. 18, 2021, 10:05 p.m. UTC
Sorry for the breakage, we need to continue processing EH edges..

Bootstrapped on x86_64-pc-linux-gnu (including Go :-)  with no 
regressions as of the original checkin.   I hope this catches all the 
other ripple PRs too.  Pushed.


> Returning NULL in gimple_range_ssa_p is probably not a good idea.  The
> name does carry a range it just has to be considered VARYING.
>
> The issue with abnormal edges is that they do not have a jump
> associated with them and thus we cannot insert code on the edge
> because we cannot split it.  That has implications for coalescing
> since we cannot even insert copies there so the PHI argument
> and the PHI result have to be the same register for the arguments
> on abnormal edges.
>
> Otherwise they do carry a value and a range but forcing that to be
> VARYING makes sense to avoid propagating constants to where
> it is not allowed (though the substitution phase should be the one
> checking).

gimple_range_ssa_p is mean to be more of a gateway into processing.  If 
its false, we wont try to find any additional range for it.  This keeps 
it out of the tables and caches, reducing processing time as well as the 
memory footprint.

We can find ranges for anything with supports_type_p() set to true,and 
it is likely to be VARYING if gimple_range_ssa_p is false now.

That said, this is the first time is been super heavily exercised in 
this regard, and there are a couple of places where we were returning 
FALSE which was less than ideal.   I should have been calling 
get_tree_range, which would then return false for non-supported types, 
or the global/varying value if they are.

And we could probably do better for at least calculating a range for 
such SSA_NAMES under these circumstances.. there is no reason we can't 
fold the stmt an get a range.  I'll tweak/audit  that in a follow up so 
there is better consistency between when we check gimple_range_ssa_p and 
irange::type_support_p()


Andrew
diff mbox series

Patch

commit 4d92a69fc5882c86aab63d52382b393d4f20b3ed
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Mon Oct 18 13:52:18 2021 -0400

    Process EH edges again and call get_tree_range on non gimple_range_ssa_p names.
    
            PR tree-optimization/102796
            gcc/
            * gimple-range.cc (gimple_ranger::range_on_edge): Process EH edges
            normally.  Return get_tree_range for non gimple_range_ssa_p names.
            (gimple_ranger::range_of_stmt): Use get_tree_range for non
            gimple_range_ssa_p names.
    
            gcc/testsuite/
            * g++.dg/pr102796.C: New.

diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index 85ef9745593..93d6da66ccb 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -180,9 +180,9 @@  gimple_ranger::range_on_edge (irange &r, edge e, tree name)
   int_range_max edge_range;
   gcc_checking_assert (irange::supports_type_p (TREE_TYPE (name)));
 
-  // Do not process values along abnormal or EH edges.
-  if (e->flags & (EDGE_ABNORMAL|EDGE_EH))
-    return false;
+  // Do not process values along abnormal edges.
+  if (e->flags & EDGE_ABNORMAL)
+    return get_tree_range (r, name, NULL);
 
   unsigned idx;
   if ((idx = tracer.header ("range_on_edge (")))
@@ -203,7 +203,7 @@  gimple_ranger::range_on_edge (irange &r, edge e, tree name)
 
   bool res = true;
   if (!gimple_range_ssa_p (name))
-    res = range_of_expr (r, name);
+    return get_tree_range (r, name, NULL);
   else
     {
       range_on_exit (r, e->src, name);
@@ -258,7 +258,7 @@  gimple_ranger::range_of_stmt (irange &r, gimple *s, tree name)
   if (!name)
     res = fold_range_internal (r, s, NULL_TREE);
   else if (!gimple_range_ssa_p (name))
-    res = false;
+    res = get_tree_range (r, name, NULL);
   // Check if the stmt has already been processed, and is not stale.
   else if (m_cache.get_non_stale_global_range (r, name))
     {
diff --git a/gcc/testsuite/g++.dg/pr102796.C b/gcc/testsuite/g++.dg/pr102796.C
new file mode 100644
index 00000000000..6ad1008922f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr102796.C
@@ -0,0 +1,18 @@ 
+// { dg-do compile }
+// { dg-options "-O3 -fno-tree-ccp -fno-tree-fre -fno-tree-forwprop -std=c++17" }
+
+namespace std {
+template <class _E>
+struct initializer_list {
+  const int* __begin_;
+  decltype(sizeof(int)) __size_;
+};
+}  // namespace std
+struct destroyme1 {};
+struct witharg1 {
+  witharg1(const destroyme1&);
+  ~witharg1();
+};
+std::initializer_list globalInitList2 = {witharg1(destroyme1()),
+                                         witharg1(destroyme1())};
+