diff mbox series

[committed] move vrp_set_zero_nonzero_bits into vr-values.c

Message ID 5fe14bcd-d21c-6838-1b7d-9f612925b155@redhat.com
State New
Headers show
Series [committed] move vrp_set_zero_nonzero_bits into vr-values.c | expand

Commit Message

Aldy Hernandez Nov. 5, 2019, 9:51 a.m. UTC
This function is only used in vr-values.c, so it doesn't need to be 
externally visible or defined in tree-vrp.c.

In moving it I noticed that wide_int_range_set_zero_nonzero_bits is 
redundant, as we can grab the version in range-op.

I've also renamed the function to vr_set_zero_nonzero_bits (removed the 
"P"), as it's more a value_range thing than a VRP thing.

Committed as obvious.
diff mbox series

Patch

commit a59ec913fa95849a356d00d211510b29eab5565f
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 5 09:48:41 2019 +0100

    Move vrp_set_zero_nonzero_bits from tree-vrp.c into vr-values.c, and
    make it use wi_set_zero_nonzero_bits.  Remove the now redundant
    wide_int_range_set_zero_nonzero_bits.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f492ea6da0c..786dee727dc 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,14 @@ 
+2019-11-05  Aldy Hernandez  <aldyh@redhat.com>
+
+	* range-op.cc (wi_set_zero_nonzero_bits): Remove static qualifier.
+	* range-op.h (wi_set_zero_nonzero_bits): New prototype.
+	* tree-vrp.h (vrp_set_zero_nonzero_bits): Remove.
+	* tree-vrp.c (wide_int_range_set_zero_nonzero_bits): Remove.
+	(vrp_set_zero_nonzero_bits): Move to...
+	* vr-values.c (vr_set_zero_nonzero_bits): ...here.
+	(vr_values::simplify_bit_ops_using_ranges): Rename
+	vrp_set_zero_nonzero_bits to vr_set_zero_nonzero_bits.
+
 2019-11-05  Aldy Hernandez  <aldyh@redhat.com>
 
 	* tree-vrp.h (vrp_bitmap_equal_p): Remove.
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index fc31485384b..56e8a20ad9e 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -1847,7 +1847,7 @@  wi_optimize_and_or (value_range_base &r,
 // for all numbers in the range the bit is 1, otherwise it might be 0
 // or 1.
 
-static void
+void
 wi_set_zero_nonzero_bits (tree type,
 			  const wide_int &lb, const wide_int &ub,
 			  wide_int &maybe_nonzero,
diff --git a/gcc/range-op.h b/gcc/range-op.h
index f6510758163..e531b918263 100644
--- a/gcc/range-op.h
+++ b/gcc/range-op.h
@@ -82,7 +82,10 @@  protected:
 };
 
 extern range_operator *range_op_handler (enum tree_code code, tree type);
-
 extern void range_cast (value_range_base &, tree type);
+extern void wi_set_zero_nonzero_bits (tree type,
+				      const wide_int &, const wide_int &,
+				      wide_int &maybe_nonzero,
+				      wide_int &mustbe_nonzero);
 
 #endif // GCC_RANGE_OP_H
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index e926670b962..e1d5c7cb98c 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -1260,69 +1260,6 @@  value_range_base::value_inside_range (tree val) const
     return !!cmp2;
 }
 
-/* For range [LB, UB] compute two wide_int bit masks.
-
-   In the MAY_BE_NONZERO bit mask, if some bit is unset, it means that
-   for all numbers in the range the bit is 0, otherwise it might be 0
-   or 1.
-
-   In the MUST_BE_NONZERO bit mask, if some bit is set, it means that
-   for all numbers in the range the bit is 1, otherwise it might be 0
-   or 1.  */
-
-static inline void
-wide_int_range_set_zero_nonzero_bits (signop sign,
-				      const wide_int &lb, const wide_int &ub,
-				      wide_int &may_be_nonzero,
-				      wide_int &must_be_nonzero)
-{
-  may_be_nonzero = wi::minus_one (lb.get_precision ());
-  must_be_nonzero = wi::zero (lb.get_precision ());
-
-  if (wi::eq_p (lb, ub))
-    {
-      may_be_nonzero = lb;
-      must_be_nonzero = may_be_nonzero;
-    }
-  else if (wi::ge_p (lb, 0, sign) || wi::lt_p (ub, 0, sign))
-    {
-      wide_int xor_mask = lb ^ ub;
-      may_be_nonzero = lb | ub;
-      must_be_nonzero = lb & ub;
-      if (xor_mask != 0)
-	{
-	  wide_int mask = wi::mask (wi::floor_log2 (xor_mask), false,
-				    may_be_nonzero.get_precision ());
-	  may_be_nonzero = may_be_nonzero | mask;
-	  must_be_nonzero = wi::bit_and_not (must_be_nonzero, mask);
-	}
-    }
-}
-
-/* value_range wrapper for wide_int_range_set_zero_nonzero_bits above.
-
-   Return TRUE if VR was a constant range and we were able to compute
-   the bit masks.  */
-
-bool
-vrp_set_zero_nonzero_bits (const tree expr_type,
-			   const value_range_base *vr,
-			   wide_int *may_be_nonzero,
-			   wide_int *must_be_nonzero)
-{
-  if (!range_int_cst_p (vr))
-    {
-      *may_be_nonzero = wi::minus_one (TYPE_PRECISION (expr_type));
-      *must_be_nonzero = wi::zero (TYPE_PRECISION (expr_type));
-      return false;
-    }
-  wide_int_range_set_zero_nonzero_bits (TYPE_SIGN (expr_type),
-					wi::to_wide (vr->min ()),
-					wi::to_wide (vr->max ()),
-					*may_be_nonzero, *must_be_nonzero);
-  return true;
-}
-
 /* Create two value-ranges in *VR0 and *VR1 from the anti-range *AR
    so that *VR0 U *VR1 == *AR.  Returns true if that is possible,
    false otherwise.  If *AR can be represented with a single range
diff --git a/gcc/tree-vrp.h b/gcc/tree-vrp.h
index 3861634fb7e..0bf33caba85 100644
--- a/gcc/tree-vrp.h
+++ b/gcc/tree-vrp.h
@@ -299,8 +299,6 @@  void range_fold_binary_expr (value_range_base *, enum tree_code, tree type,
 extern bool vrp_operand_equal_p (const_tree, const_tree);
 extern enum value_range_kind intersect_range_with_nonzero_bits
   (enum value_range_kind, wide_int *, wide_int *, const wide_int &, signop);
-extern bool vrp_set_zero_nonzero_bits (const tree, const value_range_base *,
-				       wide_int *, wide_int *);
 
 extern bool find_case_label_range (gswitch *, tree, tree, size_t *, size_t *);
 extern bool find_case_label_index (gswitch *, size_t, tree, size_t *);
diff --git a/gcc/vr-values.c b/gcc/vr-values.c
index 3acbfc60797..d1713bf4e0e 100644
--- a/gcc/vr-values.c
+++ b/gcc/vr-values.c
@@ -3341,6 +3341,30 @@  vr_values::simplify_abs_using_ranges (gimple_stmt_iterator *gsi, gimple *stmt)
   return false;
 }
 
+/* value_range wrapper for wi_set_zero_nonzero_bits.
+
+   Return TRUE if VR was a constant range and we were able to compute
+   the bit masks.  */
+
+static bool
+vr_set_zero_nonzero_bits (const tree expr_type,
+			  const value_range_base *vr,
+			  wide_int *may_be_nonzero,
+			  wide_int *must_be_nonzero)
+{
+  if (range_int_cst_p (vr))
+    {
+      wi_set_zero_nonzero_bits (expr_type,
+				wi::to_wide (vr->min ()),
+				wi::to_wide (vr->max ()),
+				*may_be_nonzero, *must_be_nonzero);
+      return true;
+    }
+  *may_be_nonzero = wi::minus_one (TYPE_PRECISION (expr_type));
+  *must_be_nonzero = wi::zero (TYPE_PRECISION (expr_type));
+  return false;
+}
+
 /* Optimize away redundant BIT_AND_EXPR and BIT_IOR_EXPR.
    If all the bits that are being cleared by & are already
    known to be zero from VR, or all the bits that are being
@@ -3373,11 +3397,11 @@  vr_values::simplify_bit_ops_using_ranges (gimple_stmt_iterator *gsi,
   else
     return false;
 
-  if (!vrp_set_zero_nonzero_bits (TREE_TYPE (op0), &vr0, &may_be_nonzero0,
-				  &must_be_nonzero0))
+  if (!vr_set_zero_nonzero_bits (TREE_TYPE (op0), &vr0, &may_be_nonzero0,
+				 &must_be_nonzero0))
     return false;
-  if (!vrp_set_zero_nonzero_bits (TREE_TYPE (op1), &vr1, &may_be_nonzero1,
-				  &must_be_nonzero1))
+  if (!vr_set_zero_nonzero_bits (TREE_TYPE (op1), &vr1, &may_be_nonzero1,
+				 &must_be_nonzero1))
     return false;
 
   switch (gimple_assign_rhs_code (stmt))