[COMMITTED] Allow ranger queries on exit block.

Message ID 052c0ba5-79fc-ad55-bfa9-38b5b3394e11@redhat.com
State Repeat Merge
Headers
Series [COMMITTED] Allow ranger queries on exit block. |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Andrew MacLeod Nov. 1, 2022, 1:19 p.m. UTC
  Ranger was not allowing the exit block to be queried for range_on_entry 
or exit, for no good reason.  This removes that restriction.

Interestingly, it seems that when we calculate dominance info, GCC does 
not set the dominators for the EXIT_BLOCK?  I worked around it by 
starting with a single pred of the exit block for my queries, but as a 
result it doesn't support multiple exit blocks.

For the record:

   get_immediate_dominator (CDI_DOMINATORS, EXIT_BLOCK_PTR_FOR_FN (cfun))

returns NULL.   Is this actually working as intended?  It was unexpected 
on my part.

Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed.

Andrew
  

Comments

Richard Biener Nov. 2, 2022, 8:18 a.m. UTC | #1
On Tue, Nov 1, 2022 at 2:20 PM Andrew MacLeod via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Ranger was not allowing the exit block to be queried for range_on_entry
> or exit, for no good reason.  This removes that restriction.
>
> Interestingly, it seems that when we calculate dominance info, GCC does
> not set the dominators for the EXIT_BLOCK?  I worked around it by
> starting with a single pred of the exit block for my queries, but as a
> result it doesn't support multiple exit blocks.
>
> For the record:
>
>    get_immediate_dominator (CDI_DOMINATORS, EXIT_BLOCK_PTR_FOR_FN (cfun))
>
> returns NULL.   Is this actually working as intended?  It was unexpected
> on my part.

Yes, working as "intended".  EXIT and ENTRY
basic-blocks are artificial so having dominance info for them would be
somewhat odd.

Richard.

>
> Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed.
>
> Andrew
  

Patch

From 592bbe3d7eb3cff656c731e84ad872719a4a9d16 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Mon, 31 Oct 2022 10:56:25 -0400
Subject: [PATCH 2/3] Allow queries on exit block.

Ranger was not allowing the exit block to be queried for range_on_entry
or exit.  This removes that restriction.

	* gimple-range-cache.cc (ranger_cache::fill_block_cache): Allow
	exit block to be specified.
	(ranger_cache::range_from_dom): If exit block is specified, use
	the immediate predecessor instead of the dominator to start.
	* gimple-range.cc (gimple_ranger::range_on_exit): Allow query
	for exit block.
---
 gcc/gimple-range-cache.cc | 16 ++++++++++------
 gcc/gimple-range.cc       |  1 -
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index f279371948a..89e2403acce 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -1193,9 +1193,8 @@  ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb)
   Value_Range block_result (type);
   Value_Range undefined (type);
 
-  // At this point we shouldn't be looking at the def, entry or exit block.
-  gcc_checking_assert (bb != def_bb && bb != ENTRY_BLOCK_PTR_FOR_FN (cfun) &&
-		       bb != EXIT_BLOCK_PTR_FOR_FN (cfun));
+  // At this point we shouldn't be looking at the def, entry block.
+  gcc_checking_assert (bb != def_bb && bb != ENTRY_BLOCK_PTR_FOR_FN (cfun));
   gcc_checking_assert (m_workback.length () == 0);
 
   // If the block cache is set, then we've already visited this block.
@@ -1434,10 +1433,15 @@  ranger_cache::range_from_dom (vrange &r, tree name, basic_block start_bb,
   // Default value is global range.
   get_global_range (r, name);
 
+  // The dominator of EXIT_BLOCK doesn't seem to be set, so at least handle
+  // the common single exit cases.
+  if (start_bb == EXIT_BLOCK_PTR_FOR_FN (cfun) && single_pred_p (start_bb))
+    bb = single_pred_edge (start_bb)->src;
+  else
+    bb = get_immediate_dominator (CDI_DOMINATORS, start_bb);
+
   // Search until a value is found, pushing blocks which may need calculating.
-  for (bb = get_immediate_dominator (CDI_DOMINATORS, start_bb);
-       bb;
-       prev_bb = bb, bb = get_immediate_dominator (CDI_DOMINATORS, bb))
+  for ( ; bb; prev_bb = bb, bb = get_immediate_dominator (CDI_DOMINATORS, bb))
     {
       // Accumulate any block exit inferred ranges.
       m_exit.maybe_adjust_range (infer, name, bb);
diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index 058439733ee..110cf574454 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -167,7 +167,6 @@  void
 gimple_ranger::range_on_exit (vrange &r, basic_block bb, tree name)
 {
   // on-exit from the exit block?
-  gcc_checking_assert (bb != EXIT_BLOCK_PTR_FOR_FN (cfun));
   gcc_checking_assert (gimple_range_ssa_p (name));
 
   unsigned idx;
-- 
2.37.3