[COMMITTED] Use TYPE_MIN/MAX_VALUE in set_varying when possible.

Message ID 6d270ef8-e297-8159-c9b1-8e4b475a41d5@redhat.com
State Committed
Headers
Series [COMMITTED] Use TYPE_MIN/MAX_VALUE in set_varying when possible. |

Commit Message

Andrew MacLeod Oct. 6, 2021, 2:53 p.m. UTC
  We set the upper and lower bounds in an irange whenever we call 
set_varying (). Unfortunately, we create a new tree for the bounds each 
time, and this is quite expensive.. creating a lot of unnecessary work.

This patch will use the values of TYPE_MIN_VALUE and TYPE_MAX_VALUE if 
possible, instead of creating new trees.  We cant simply use it always 
because a) pointers dont have such a thing, and b) enum types require 
varying to have the range of the underlying type rather than the range 
of the enum as reflected by the macros.

Regardless, even with the requisite checks this produces decent 
results.  Over a set of 380 GCC source files, it produces a further 4.5% 
speedup in EVRP.

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

Andrew
  

Patch

From e828f4b5898896240b2ae5d5030c539aff28ea24 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Tue, 28 Sep 2021 13:11:22 -0400
Subject: [PATCH 2/4] Use TYPE_MIN/MAX_VALUE in set_varying when possible.

We currently create new trees every time... which is very wasteful and time
consuming. Instead, just use the TYPE_MIN/MAX_VALUE.

	* value-range.h (irange::set_varying): Use TYPE_MIN_VALUE and
	TYPE_MAX_VALUE instead of creating new trees when possible.
---
 gcc/value-range.h | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/gcc/value-range.h b/gcc/value-range.h
index a8adc50b98e..39e8f3bcdee 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -476,10 +476,21 @@  irange::set_varying (tree type)
 
   if (INTEGRAL_TYPE_P (type))
     {
+      // Strict enum's require varying to be not TYPE_MIN/MAX, but rather
+      // min_value and max_value.
       wide_int min = wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type));
       wide_int max = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
-      m_base[0] = wide_int_to_tree (type, min);
-      m_base[1] = wide_int_to_tree (type, max);
+      if (wi::eq_p (max, wi::to_wide (TYPE_MAX_VALUE (type)))
+	  && wi::eq_p (min, wi::to_wide (TYPE_MIN_VALUE (type))))
+	{
+	  m_base[0] = TYPE_MIN_VALUE (type);
+	  m_base[1] = TYPE_MAX_VALUE (type);
+	}
+      else
+	{
+	  m_base[0] = wide_int_to_tree (type, min);
+	  m_base[1] = wide_int_to_tree (type, max);
+	}
     }
   else if (POINTER_TYPE_P (type))
     {
-- 
2.17.2