[PATCH] Add double_int_sub

Richard Guenther rguenther@suse.de
Mon Jul 5 12:37:00 GMT 2010


This adds double_int_sub, a short-cut for
double_int_add (x, double_int_neg (y)).  This has the chance to be
better optimized in double-int.c and allows writing shorter
and easier to grok source.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Will commit if that succeeded.

Richard.

2010-07-05  Richard Guenther  <rguenther@suse.de>

	* double-int.h (double_int_sub): Declare.
	* double-int.c (double_int_sub): New function.
	* dwarf2out.c (field_byte_offset): Use it.
	* fixed-value.c (do_fixed_add): Likewise.
	(do_fixed_multiply): Likewise.
	(do_fixed_divide): Likewise.
	* tree-predcom.c (add_ref_to_chain): Likewise.
	(determine_roots_comp): Likewise.
	* tree-ssa-loop-niter.c (derive_constant_upper_bound_ops): Likewise.

Index: gcc/double-int.h
===================================================================
*** gcc/double-int.h	(revision 161820)
--- gcc/double-int.h	(working copy)
*************** double_int_fits_in_uhwi_p (double_int cs
*** 133,138 ****
--- 133,139 ----
  
  double_int double_int_mul (double_int, double_int);
  double_int double_int_add (double_int, double_int);
+ double_int double_int_sub (double_int, double_int);
  double_int double_int_neg (double_int);
  
  /* You must ensure that double_int_ext is called on the operands
Index: gcc/double-int.c
===================================================================
*** gcc/double-int.c	(revision 161820)
--- gcc/double-int.c	(working copy)
*************** double_int_add (double_int a, double_int
*** 792,797 ****
--- 792,808 ----
    return ret;
  }
  
+ /* Returns A - B.  */
+ 
+ double_int
+ double_int_sub (double_int a, double_int b)
+ {
+   double_int ret;
+   neg_double (b.low, b.high, &b.low, &b.high);
+   add_double (a.low, a.high, b.low, b.high, &ret.low, &ret.high);
+   return ret;
+ }
+ 
  /* Returns -A.  */
  
  double_int
Index: gcc/dwarf2out.c
===================================================================
*** gcc/dwarf2out.c	(revision 161820)
--- gcc/dwarf2out.c	(working copy)
*************** field_byte_offset (const_tree decl)
*** 15746,15752 ****
  	 where the lowest addressed bit of the containing object must
  	 be.  */
        object_offset_in_bits
! 	= double_int_add (deepest_bitpos, double_int_neg (type_size_in_bits));
  
        /* Round up to type_align by default.  This works best for
  	 bitfields.  */
--- 15746,15752 ----
  	 where the lowest addressed bit of the containing object must
  	 be.  */
        object_offset_in_bits
! 	= double_int_sub (deepest_bitpos, type_size_in_bits);
  
        /* Round up to type_align by default.  This works best for
  	 bitfields.  */
*************** field_byte_offset (const_tree decl)
*** 15756,15763 ****
        if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
  	{
  	  object_offset_in_bits
! 	    = double_int_add (deepest_bitpos,
! 			      double_int_neg (type_size_in_bits));
  
  	  /* Round up to decl_align instead.  */
  	  object_offset_in_bits
--- 15756,15762 ----
        if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
  	{
  	  object_offset_in_bits
! 	    = double_int_sub (deepest_bitpos, type_size_in_bits);
  
  	  /* Round up to decl_align instead.  */
  	  object_offset_in_bits
Index: gcc/fixed-value.c
===================================================================
*** gcc/fixed-value.c	(revision 161820)
--- gcc/fixed-value.c	(working copy)
*************** do_fixed_add (FIXED_VALUE_TYPE *f, const
*** 361,367 ****
  		  double_int one;
  		  one.low = 1;
  		  one.high = 0;
! 		  f->data = double_int_add (f->data, double_int_neg (one));
  		}
  	    }
  	  else
--- 361,367 ----
  		  double_int one;
  		  one.low = 1;
  		  one.high = 0;
! 		  f->data = double_int_sub (f->data, one);
  		}
  	    }
  	  else
*************** do_fixed_multiply (FIXED_VALUE_TYPE *f,
*** 443,454 ****
        temp1.high = 0;
        r = double_int_add (r, temp1);
  
!       /* We need to add neg(b) to r, if a < 0.  */
        if (!unsigned_p && a->data.high < 0)
! 	r = double_int_add (r, double_int_neg (b->data));
!       /* We need to add neg(a) to r, if b < 0.  */
        if (!unsigned_p && b->data.high < 0)
! 	r = double_int_add (r, double_int_neg (a->data));
  
        /* Shift right the result by FBIT.  */
        if (GET_MODE_FBIT (f->mode) == 2 * HOST_BITS_PER_WIDE_INT)
--- 443,454 ----
        temp1.high = 0;
        r = double_int_add (r, temp1);
  
!       /* We need to subtract b from r, if a < 0.  */
        if (!unsigned_p && a->data.high < 0)
! 	r = double_int_sub (r, b->data);
!       /* We need to subtract a from r, if b < 0.  */
        if (!unsigned_p && b->data.high < 0)
! 	r = double_int_sub (r, a->data);
  
        /* Shift right the result by FBIT.  */
        if (GET_MODE_FBIT (f->mode) == 2 * HOST_BITS_PER_WIDE_INT)
*************** do_fixed_divide (FIXED_VALUE_TYPE *f, co
*** 588,594 ****
  			 &quo_s.low, &quo_s.high, 0);
  
  	  /* Try to calculate (mod - pos_b).  */
! 	  temp = double_int_add (mod, double_int_neg (pos_b));
  
  	  if (leftmost_mod == 1 || double_int_cmp (mod, pos_b, 1) != -1)
  	    {
--- 588,594 ----
  			 &quo_s.low, &quo_s.high, 0);
  
  	  /* Try to calculate (mod - pos_b).  */
! 	  temp = double_int_sub (mod, pos_b);
  
  	  if (leftmost_mod == 1 || double_int_cmp (mod, pos_b, 1) != -1)
  	    {
Index: gcc/tree-predcom.c
===================================================================
*** gcc/tree-predcom.c	(revision 161820)
--- gcc/tree-predcom.c	(working copy)
*************** add_ref_to_chain (chain_p chain, dref re
*** 925,931 ****
    double_int dist;
  
    gcc_assert (double_int_scmp (root->offset, ref->offset) <= 0);
!   dist = double_int_add (ref->offset, double_int_neg (root->offset));
    if (double_int_ucmp (uhwi_to_double_int (MAX_DISTANCE), dist) <= 0)
      {
        free (ref);
--- 925,931 ----
    double_int dist;
  
    gcc_assert (double_int_scmp (root->offset, ref->offset) <= 0);
!   dist = double_int_sub (ref->offset, root->offset);
    if (double_int_ucmp (uhwi_to_double_int (MAX_DISTANCE), dist) <= 0)
      {
        free (ref);
*************** determine_roots_comp (struct loop *loop,
*** 1199,1206 ****
      {
        if (!chain || !DR_IS_READ (a->ref)
  	  || double_int_ucmp (uhwi_to_double_int (MAX_DISTANCE),
! 			      double_int_add (a->offset,
! 					      double_int_neg (last_ofs))) <= 0)
  	{
  	  if (nontrivial_chain_p (chain))
  	    {
--- 1199,1205 ----
      {
        if (!chain || !DR_IS_READ (a->ref)
  	  || double_int_ucmp (uhwi_to_double_int (MAX_DISTANCE),
! 			      double_int_sub (a->offset, last_ofs)) <= 0)
  	{
  	  if (nontrivial_chain_p (chain))
  	    {
Index: gcc/tree-ssa-loop-niter.c
===================================================================
*** gcc/tree-ssa-loop-niter.c	(revision 161820)
--- gcc/tree-ssa-loop-niter.c	(working copy)
*************** derive_constant_upper_bound_ops (tree ty
*** 2397,2403 ****
  	  /* OP0 + CST.  We need to check that
  	     BND <= MAX (type) - CST.  */
  
! 	  mmax = double_int_add (max, double_int_neg (cst));
  	  if (double_int_ucmp (bnd, mmax) > 0)
  	    return max;
  
--- 2397,2403 ----
  	  /* OP0 + CST.  We need to check that
  	     BND <= MAX (type) - CST.  */
  
! 	  mmax = double_int_sub (max, cst);
  	  if (double_int_ucmp (bnd, mmax) > 0)
  	    return max;
  
*************** derive_constant_upper_bound_ops (tree ty
*** 2429,2435 ****
  		return max;
  	    }
  
! 	  bnd = double_int_add (bnd, double_int_neg (cst));
  	}
  
        return bnd;
--- 2429,2435 ----
  		return max;
  	    }
  
! 	  bnd = double_int_sub (bnd, cst);
  	}
  
        return bnd;



More information about the Gcc-patches mailing list