public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [optimize 2/3] Simplify vrp abs conversion
@ 2015-08-10 21:48 Nathan Sidwell
  2015-08-11 11:33 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Sidwell @ 2015-08-10 21:48 UTC (permalink / raw)
  To: Richard Guenther; +Cc: GCC Patches

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

Richard,
in looking at how simplify_abs_using_ranges was doing its thing as a guide to a 
min/max vrp optimization, I noticed it was doing more work than necessary.

Firstly, it wasn't taking advantage of the range comparison functions only 
returning TRUE or FALSE nodes when there's a definite answer, and NULL 
otherwise.  Thus if we get a node, we don't have to (a) check if it's either 
true or false and (b) we only need to check for one of those values to determine 
which specific answer was given.

Also, it was checking for 'NOT (A >= B)' by inverting the result of a '>=' 
check, rather than simply doing a '<' check. (we're dealing with integer ranges, 
so that's all well defined)

Finally, there's a useless check for UNSIGNED_TYPE, which ends up doing nothing. 
  AFAICT 'ABS (unsigned)' gets folded out very early on.

booted and tested with the phi-min-max fix I just posted and the new VRP-min-max 
optimization I'm about to.

ok?

nathan


[-- Attachment #2: vrp-abs-simple.patch --]
[-- Type: text/x-patch, Size: 1750 bytes --]

2015-08-10  Nathan Sidwell  <nathan@acm.org>

	* tree-vrp.c (simplify_abs_using_ranges): Simplify.

Index: tree-vrp.c
===================================================================
--- tree-vrp.c	(revision 226749)
+++ tree-vrp.c	(working copy)
@@ -9152,37 +9215,25 @@ simplify_div_or_mod_using_ranges (gimple
 static bool
 simplify_abs_using_ranges (gimple stmt)
 {
-  tree val = NULL;
   tree op = gimple_assign_rhs1 (stmt);
-  tree type = TREE_TYPE (op);
   value_range_t *vr = get_value_range (op);
 
-  if (TYPE_UNSIGNED (type))
-    {
-      val = integer_zero_node;
-    }
-  else if (vr)
+  if (vr)
     {
+      tree val = NULL;
       bool sop = false;
 
       val = compare_range_with_value (LE_EXPR, vr, integer_zero_node, &sop);
       if (!val)
 	{
+	  /* The range is neither <= 0 nor > 0.  Now see if it is
+	     either < 0 or >= 0.  */
 	  sop = false;
-	  val = compare_range_with_value (GE_EXPR, vr, integer_zero_node,
+	  val = compare_range_with_value (LT_EXPR, vr, integer_zero_node,
 					  &sop);
-
-	  if (val)
-	    {
-	      if (integer_zerop (val))
-		val = integer_one_node;
-	      else if (integer_onep (val))
-		val = integer_zero_node;
-	    }
 	}
 
-      if (val
-	  && (integer_onep (val) || integer_zerop (val)))
+      if (val)
 	{
 	  if (sop && issue_strict_overflow_warning (WARN_STRICT_OVERFLOW_MISC))
 	    {
@@ -9198,10 +9249,10 @@ simplify_abs_using_ranges (gimple stmt)
 	    }
 
 	  gimple_assign_set_rhs1 (stmt, op);
-	  if (integer_onep (val))
-	    gimple_assign_set_rhs_code (stmt, NEGATE_EXPR);
-	  else
+	  if (integer_zerop (val))
 	    gimple_assign_set_rhs_code (stmt, SSA_NAME);
+	  else
+	    gimple_assign_set_rhs_code (stmt, NEGATE_EXPR);
 	  update_stmt (stmt);
 	  return true;
 	}

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

* Re: [optimize 2/3] Simplify vrp abs conversion
  2015-08-10 21:48 [optimize 2/3] Simplify vrp abs conversion Nathan Sidwell
@ 2015-08-11 11:33 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2015-08-11 11:33 UTC (permalink / raw)
  To: Nathan Sidwell; +Cc: GCC Patches

On Mon, 10 Aug 2015, Nathan Sidwell wrote:

> Richard,
> in looking at how simplify_abs_using_ranges was doing its thing as a guide to
> a min/max vrp optimization, I noticed it was doing more work than necessary.
> 
> Firstly, it wasn't taking advantage of the range comparison functions only
> returning TRUE or FALSE nodes when there's a definite answer, and NULL
> otherwise.  Thus if we get a node, we don't have to (a) check if it's either
> true or false and (b) we only need to check for one of those values to
> determine which specific answer was given.
> 
> Also, it was checking for 'NOT (A >= B)' by inverting the result of a '>='
> check, rather than simply doing a '<' check. (we're dealing with integer
> ranges, so that's all well defined)
> 
> Finally, there's a useless check for UNSIGNED_TYPE, which ends up doing
> nothing.  AFAICT 'ABS (unsigned)' gets folded out very early on.
> 
> booted and tested with the phi-min-max fix I just posted and the new
> VRP-min-max optimization I'm about to.
> 
> ok?

Ok.

Thanks,
Richard.

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

end of thread, other threads:[~2015-08-11 11:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-10 21:48 [optimize 2/3] Simplify vrp abs conversion Nathan Sidwell
2015-08-11 11:33 ` Richard Biener

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