public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tweak range-on-exit.
@ 2021-05-07 19:03 Andrew MacLeod
  2021-05-08 15:05 ` Aldy Hernandez
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew MacLeod @ 2021-05-07 19:03 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 605 bytes --]

Range on exit was not ding the right thing when a basic block contained 
no statements other than a PHI node.

Rather than returning the value of the PHI, it was instead asking for 
range-on-entry for the phi, which  would trigger a walk back to the top 
of the CFG looking for the definition. When it didnt find it, it would 
then default to the global-value calculation. So it ended up with the 
right value, but it does a lot of unnecessary work and put entries in 
the on-entry cache that don't need to be there.

Bootstraps on  x86_64-pc-linux-gnu with no testsuite regressions.

Pushed.

Andrew



[-- Attachment #2: 5.phi-calc.patch --]
[-- Type: text/x-patch, Size: 1950 bytes --]

commit c0c25d1052950cecbf4488b7f76d41952672414a
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Mon Apr 26 19:23:25 2021 -0400

    Fix range_on_exit for PHI stmts when there are no other stmts in the block.
    
    last_stmt(bb) returns NULL for blocks which only have PHI stmts, and
    range_on_exit would trigger a cache fill all the way to the top of the
    program for the SSA_NAME.
    
            * gimple-range.cc (gimple_ranger::range_on_exit): Handle block with
            only PHI nodes better.

diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index 6158a754dd6..e94bb355de3 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -1003,14 +1003,23 @@ gimple_ranger::range_on_exit (irange &r, basic_block bb, tree name)
   gcc_checking_assert (bb != EXIT_BLOCK_PTR_FOR_FN (cfun));
   gcc_checking_assert (gimple_range_ssa_p (name));
 
-  gimple *s = last_stmt (bb);
-  // If there is no statement in the block and this isn't the entry
-  // block, go get the range_on_entry for this block.  For the entry
-  // block, a NULL stmt will return the global value for NAME.
-  if (!s && bb != ENTRY_BLOCK_PTR_FOR_FN (cfun))
-    range_on_entry (r, bb, name);
-  else
+  gimple *s = SSA_NAME_DEF_STMT (name);
+  basic_block def_bb = gimple_bb (s);
+  // If this is not the definition block, get the range on the last stmt in
+  // the block... if there is one.
+  if (def_bb != bb)
+    s = last_stmt (bb);
+  // If there is no statement provided, get the range_on_entry for this block.
+  if (s)
     range_of_expr (r, name, s);
+  else
+    {
+      range_on_entry (r, bb, name);
+      // See if there was a deref in this block, if applicable
+      if (!cfun->can_throw_non_call_exceptions && r.varying_p () &&
+	  m_cache.m_non_null.non_null_deref_p (name, bb))
+	r = range_nonzero (TREE_TYPE (name));
+    }
   gcc_checking_assert (r.undefined_p ()
 		       || range_compatible_p (r.type (), TREE_TYPE (name)));
 }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] tweak range-on-exit.
  2021-05-07 19:03 [PATCH] tweak range-on-exit Andrew MacLeod
@ 2021-05-08 15:05 ` Aldy Hernandez
  0 siblings, 0 replies; 2+ messages in thread
From: Aldy Hernandez @ 2021-05-08 15:05 UTC (permalink / raw)
  To: Andrew MacLeod, gcc-patches



On 5/7/21 9:03 PM, Andrew MacLeod wrote:

> +  else
> +    {
> +      range_on_entry (r, bb, name);
> +      // See if there was a deref in this block, if applicable
> +      if (!cfun->can_throw_non_call_exceptions && r.varying_p () &&
> +	  m_cache.m_non_null.non_null_deref_p (name, bb))
> +	r = range_nonzero (TREE_TYPE (name));
> +    }

Nit.  The final && must go on the following line.  And it probably looks 
better if you put each "&& conditional" on its own line.

Aldy


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-08 15:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07 19:03 [PATCH] tweak range-on-exit Andrew MacLeod
2021-05-08 15:05 ` Aldy Hernandez

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).