diff mbox

wide-int, loop

Message ID 6D69A7D7-1E86-4477-81CD-EB8C3550E17C@comcast.net
State New
Headers show

Commit Message

Mike Stump Nov. 23, 2013, 7:22 p.m. UTC
Richi has asked the we break the wide-int patch so that the individual port and front end maintainers can review their parts without have to go through the entire patch.    This patch covers the loop code.

Ok?
* loop-doloop.c
	(doloop_modify): Use wide-int interfaces.
	(doloop_optimize): Likewise.
	* loop-iv.c
	(iv_number_of_iterations): Use wide-int interfaces.
	* loop-unroll.c
	(decide_unroll_constant_iterations): Use wide-int interfaces.
	(unroll_loop_constant_iterations): Likewise.
	(decide_unroll_runtime_iterations): Likewise.
	(unroll_loop_runtime_iterations): Likewise.
	(decide_peel_simple): Likewise.
	(decide_unroll_stupid): Likewise.

Comments

Richard Biener Nov. 25, 2013, 11:04 a.m. UTC | #1
On Sat, Nov 23, 2013 at 8:22 PM, Mike Stump <mikestump@comcast.net> wrote:
> Richi has asked the we break the wide-int patch so that the individual port and front end maintainers can review their parts without have to go through the entire patch.    This patch covers the loop code.
>
> Ok?

@@ -2662,8 +2661,8 @@ iv_number_of_iterations (struct loop *loop, rtx
insn, rtx condition,
       iv1.step = const0_rtx;
       if (INTVAL (iv0.step) < 0)
        {
-         iv0.step = simplify_gen_unary (NEG, comp_mode, iv0.step, mode);
-         iv1.base = simplify_gen_unary (NEG, comp_mode, iv1.base, mode);
+         iv0.step = simplify_gen_unary (NEG, comp_mode, iv0.step, comp_mode);
+         iv1.base = simplify_gen_unary (NEG, comp_mode, iv1.base, comp_mode);
        }
       iv0.step = lowpart_subreg (mode, iv0.step, comp_mode);

separate bugfix?

@@ -1378,7 +1368,8 @@ decide_peel_simple (struct loop *loop, int flags)
   /* If we have realistic estimate on number of iterations, use it.  */
   if (get_estimated_loop_iterations (loop, &iterations))
     {
-      if (double_int::from_shwi (npeel).ule (iterations))
+      /* TODO: unsigned/signed confusion */
+      if (wi::leu_p (npeel, iterations))
        {
          if (dump_file)
            {

what does this refer to?  npeel is unsigned.

Otherwise looks good to me.

Thanks,
Richard.
Kenneth Zadeck Nov. 25, 2013, 3:49 p.m. UTC | #2
On 11/25/2013 06:04 AM, Richard Biener wrote:
> On Sat, Nov 23, 2013 at 8:22 PM, Mike Stump <mikestump@comcast.net> wrote:
>> Richi has asked the we break the wide-int patch so that the individual port and front end maintainers can review their parts without have to go through the entire patch.    This patch covers the loop code.
>>
>> Ok?
> @@ -2662,8 +2661,8 @@ iv_number_of_iterations (struct loop *loop, rtx
> insn, rtx condition,
>         iv1.step = const0_rtx;
>         if (INTVAL (iv0.step) < 0)
>          {
> -         iv0.step = simplify_gen_unary (NEG, comp_mode, iv0.step, mode);
> -         iv1.base = simplify_gen_unary (NEG, comp_mode, iv1.base, mode);
> +         iv0.step = simplify_gen_unary (NEG, comp_mode, iv0.step, comp_mode);
> +         iv1.base = simplify_gen_unary (NEG, comp_mode, iv1.base, comp_mode);
>          }
>         iv0.step = lowpart_subreg (mode, iv0.step, comp_mode);
>
> separate bugfix?
most likely.    i will submit separately.
> @@ -1378,7 +1368,8 @@ decide_peel_simple (struct loop *loop, int flags)
>     /* If we have realistic estimate on number of iterations, use it.  */
>     if (get_estimated_loop_iterations (loop, &iterations))
>       {
> -      if (double_int::from_shwi (npeel).ule (iterations))
> +      /* TODO: unsigned/signed confusion */
> +      if (wi::leu_p (npeel, iterations))
>          {
>            if (dump_file)
>              {
>
> what does this refer to?  npeel is unsigned.

it was the fact that they were doing the from_shwi and then using an 
unsigned test.
> Otherwise looks good to me.
>
> Thanks,
> Richard.
Richard Biener Nov. 26, 2013, 9:14 a.m. UTC | #3
On Mon, Nov 25, 2013 at 4:49 PM, Kenneth Zadeck
<zadeck@naturalbridge.com> wrote:
>
> On 11/25/2013 06:04 AM, Richard Biener wrote:
>>
>> On Sat, Nov 23, 2013 at 8:22 PM, Mike Stump <mikestump@comcast.net> wrote:
>>>
>>> Richi has asked the we break the wide-int patch so that the individual
>>> port and front end maintainers can review their parts without have to go
>>> through the entire patch.    This patch covers the loop code.
>>>
>>> Ok?
>>
>> @@ -2662,8 +2661,8 @@ iv_number_of_iterations (struct loop *loop, rtx
>> insn, rtx condition,
>>         iv1.step = const0_rtx;
>>         if (INTVAL (iv0.step) < 0)
>>          {
>> -         iv0.step = simplify_gen_unary (NEG, comp_mode, iv0.step, mode);
>> -         iv1.base = simplify_gen_unary (NEG, comp_mode, iv1.base, mode);
>> +         iv0.step = simplify_gen_unary (NEG, comp_mode, iv0.step,
>> comp_mode);
>> +         iv1.base = simplify_gen_unary (NEG, comp_mode, iv1.base,
>> comp_mode);
>>          }
>>         iv0.step = lowpart_subreg (mode, iv0.step, comp_mode);
>>
>> separate bugfix?
>
> most likely.    i will submit separately.
>
>> @@ -1378,7 +1368,8 @@ decide_peel_simple (struct loop *loop, int flags)
>>     /* If we have realistic estimate on number of iterations, use it.  */
>>     if (get_estimated_loop_iterations (loop, &iterations))
>>       {
>> -      if (double_int::from_shwi (npeel).ule (iterations))
>> +      /* TODO: unsigned/signed confusion */
>> +      if (wi::leu_p (npeel, iterations))
>>          {
>>            if (dump_file)
>>              {
>>
>> what does this refer to?  npeel is unsigned.
>
>
> it was the fact that they were doing the from_shwi and then using an
> unsigned test.

Ah - probably a typo.  Please just remove the "TODO".

Richard.

>> Otherwise looks good to me.
>>
>> Thanks,
>> Richard.
>
>
diff mbox

Patch

diff --git a/gcc/loop-doloop.c b/gcc/loop-doloop.c
index 24e0201..0afd79d 100644
--- a/gcc/loop-doloop.c
+++ b/gcc/loop-doloop.c
@@ -409,7 +409,7 @@  doloop_modify (struct loop *loop, struct niter_desc *desc,
   basic_block loop_end = desc->out_edge->src;
   enum machine_mode mode;
   rtx true_prob_val;
-  double_int iterations;
+  widest_int iterations;
 
   jump_insn = BB_END (loop_end);
 
@@ -461,9 +461,9 @@  doloop_modify (struct loop *loop, struct niter_desc *desc,
       /* Determine if the iteration counter will be non-negative.
 	 Note that the maximum value loaded is iterations_max - 1.  */
       if (get_max_loop_iterations (loop, &iterations)
-	  && (iterations.ule (double_int_one.llshift
-			       (GET_MODE_PRECISION (mode) - 1,
-				GET_MODE_PRECISION (mode)))))
+	  && wi::leu_p (iterations,
+			wi::set_bit_in_zero <widest_int>
+			(GET_MODE_PRECISION (mode) - 1)))
 	nonneg = 1;
       break;
 
@@ -597,7 +597,7 @@  doloop_optimize (struct loop *loop)
   enum machine_mode mode;
   rtx doloop_seq, doloop_pat, doloop_reg;
   rtx count;
-  double_int iterations, iterations_max;
+  widest_int iterations, iterations_max;
   rtx start_label;
   rtx condition;
   unsigned level, est_niter;
@@ -655,11 +655,12 @@  doloop_optimize (struct loop *loop)
     }
 
   if (desc->const_iter)
-    iterations = rtx_to_double_int (desc->niter_expr);
+    iterations = widest_int::from (std::make_pair (desc->niter_expr, mode),
+				   UNSIGNED);
   else
-    iterations = double_int_zero;
+    iterations = 0;
   if (!get_max_loop_iterations (loop, &iterations_max))
-    iterations_max = double_int_zero;
+    iterations_max = 0;
   level = get_loop_level (loop) + 1;
   entered_at_top = (loop->latch == desc->in_edge->dest
 		    && contains_no_active_insn_p (loop->latch));
@@ -688,7 +689,7 @@  doloop_optimize (struct loop *loop)
 	 computed, we must be sure that the number of iterations fits into
 	 the new mode.  */
       && (word_mode_size >= GET_MODE_PRECISION (mode)
-	  || iterations_max.ule (double_int::from_shwi (word_mode_max))))
+ 	  || wi::leu_p (iterations_max, word_mode_max)))
     {
       if (word_mode_size > GET_MODE_PRECISION (mode))
 	count = simplify_gen_unary (ZERO_EXTEND, word_mode, count, mode);
diff --git a/gcc/loop-iv.c b/gcc/loop-iv.c
index c01ee17..01f8dce 100644
--- a/gcc/loop-iv.c
+++ b/gcc/loop-iv.c
@@ -2622,8 +2622,7 @@  iv_number_of_iterations (struct loop *loop, rtx insn, rtx condition,
 	  max = (up - down) / inc + 1;
 	  if (!desc->infinite
 	      && !desc->assumptions)
-	    record_niter_bound (loop, double_int::from_uhwi (max),
-			        false, true);
+	    record_niter_bound (loop, max, false, true);
 
 	  if (iv0.step == const0_rtx)
 	    {
@@ -2662,8 +2661,8 @@  iv_number_of_iterations (struct loop *loop, rtx insn, rtx condition,
       iv1.step = const0_rtx;
       if (INTVAL (iv0.step) < 0)
 	{
-	  iv0.step = simplify_gen_unary (NEG, comp_mode, iv0.step, mode);
-	  iv1.base = simplify_gen_unary (NEG, comp_mode, iv1.base, mode);
+	  iv0.step = simplify_gen_unary (NEG, comp_mode, iv0.step, comp_mode);
+	  iv1.base = simplify_gen_unary (NEG, comp_mode, iv1.base, comp_mode);
 	}
       iv0.step = lowpart_subreg (mode, iv0.step, comp_mode);
 
@@ -2837,8 +2836,7 @@  iv_number_of_iterations (struct loop *loop, rtx insn, rtx condition,
       desc->niter = val & GET_MODE_MASK (desc->mode);
       if (!desc->infinite
 	  && !desc->assumptions)
-        record_niter_bound (loop, double_int::from_uhwi (desc->niter),
-			    false, true);
+        record_niter_bound (loop, desc->niter, false, true);
     }
   else
     {
@@ -2847,8 +2845,7 @@  iv_number_of_iterations (struct loop *loop, rtx insn, rtx condition,
 	goto zero_iter_simplify;
       if (!desc->infinite
 	  && !desc->assumptions)
-	record_niter_bound (loop, double_int::from_uhwi (max),
-			    false, true);
+	record_niter_bound (loop, max, false, true);
 
       /* simplify_using_initial_values does a copy propagation on the registers
 	 in the expression for the number of iterations.  This prolongs life
@@ -2873,8 +2870,7 @@  zero_iter_simplify:
 zero_iter:
   desc->const_iter = true;
   desc->niter = 0;
-  record_niter_bound (loop, double_int_zero,
-		      true, true);
+  record_niter_bound (loop, 0, true, true);
   desc->noloop_assumptions = NULL_RTX;
   desc->niter_expr = const0_rtx;
   return;
diff --git a/gcc/loop-unroll.c b/gcc/loop-unroll.c
index 9c87167..c0d61b2 100644
--- a/gcc/loop-unroll.c
+++ b/gcc/loop-unroll.c
@@ -641,7 +641,7 @@  decide_unroll_constant_iterations (struct loop *loop, int flags)
 {
   unsigned nunroll, nunroll_by_av, best_copies, best_unroll = 0, n_copies, i;
   struct niter_desc *desc;
-  double_int iterations;
+  widest_int iterations;
 
   if (!(flags & UAP_UNROLL))
     {
@@ -691,7 +691,7 @@  decide_unroll_constant_iterations (struct loop *loop, int flags)
   if (desc->niter < 2 * nunroll
       || ((get_estimated_loop_iterations (loop, &iterations)
 	   || get_max_loop_iterations (loop, &iterations))
-	  && iterations.ult (double_int::from_shwi (2 * nunroll))))
+	  && wi::ltu_p (iterations, 2 * nunroll)))
     {
       if (dump_file)
 	fprintf (dump_file, ";; Not unrolling loop, doesn't roll\n");
@@ -811,11 +811,10 @@  unroll_loop_constant_iterations (struct loop *loop)
 
 	  desc->noloop_assumptions = NULL_RTX;
 	  desc->niter -= exit_mod;
-	  loop->nb_iterations_upper_bound -= double_int::from_uhwi (exit_mod);
+	  loop->nb_iterations_upper_bound -= exit_mod;
 	  if (loop->any_estimate
-	      && double_int::from_uhwi (exit_mod).ule
-	           (loop->nb_iterations_estimate))
-	    loop->nb_iterations_estimate -= double_int::from_uhwi (exit_mod);
+	      && wi::leu_p (exit_mod, loop->nb_iterations_estimate))
+	    loop->nb_iterations_estimate -= exit_mod;
 	  else
 	    loop->any_estimate = false;
 	}
@@ -855,11 +854,10 @@  unroll_loop_constant_iterations (struct loop *loop)
   	    apply_opt_in_copies (opt_info, exit_mod + 1, false, false);
 
 	  desc->niter -= exit_mod + 1;
-	  loop->nb_iterations_upper_bound -= double_int::from_uhwi (exit_mod + 1);
+	  loop->nb_iterations_upper_bound -= exit_mod + 1;
 	  if (loop->any_estimate
-	      && double_int::from_uhwi (exit_mod + 1).ule
-	           (loop->nb_iterations_estimate))
-	    loop->nb_iterations_estimate -= double_int::from_uhwi (exit_mod + 1);
+	      && wi::leu_p (exit_mod + 1, loop->nb_iterations_estimate))
+	    loop->nb_iterations_estimate -= exit_mod + 1;
 	  else
 	    loop->any_estimate = false;
 	  desc->noloop_assumptions = NULL_RTX;
@@ -911,14 +909,10 @@  unroll_loop_constant_iterations (struct loop *loop)
 
   desc->niter /= max_unroll + 1;
   loop->nb_iterations_upper_bound
-    = loop->nb_iterations_upper_bound.udiv (double_int::from_uhwi (max_unroll
-								   + 1),
-					    TRUNC_DIV_EXPR);
+    = wi::udiv_trunc (loop->nb_iterations_upper_bound, max_unroll + 1);
   if (loop->any_estimate)
     loop->nb_iterations_estimate
-      = loop->nb_iterations_estimate.udiv (double_int::from_uhwi (max_unroll
-							          + 1),
-				           TRUNC_DIV_EXPR);
+      = wi::udiv_trunc (loop->nb_iterations_estimate, max_unroll + 1);
   desc->niter_expr = GEN_INT (desc->niter);
 
   /* Remove the edges.  */
@@ -938,7 +932,7 @@  decide_unroll_runtime_iterations (struct loop *loop, int flags)
 {
   unsigned nunroll, nunroll_by_av, i;
   struct niter_desc *desc;
-  double_int iterations;
+  widest_int iterations;
 
   if (!(flags & UAP_UNROLL))
     {
@@ -994,7 +988,7 @@  decide_unroll_runtime_iterations (struct loop *loop, int flags)
   /* Check whether the loop rolls.  */
   if ((get_estimated_loop_iterations (loop, &iterations)
        || get_max_loop_iterations (loop, &iterations))
-      && iterations.ult (double_int::from_shwi (2 * nunroll)))
+      && wi::ltu_p (iterations, 2 * nunroll))
     {
       if (dump_file)
 	fprintf (dump_file, ";; Not unrolling loop, doesn't roll\n");
@@ -1301,14 +1295,10 @@  unroll_loop_runtime_iterations (struct loop *loop)
     simplify_gen_binary (UDIV, desc->mode, old_niter,
 			 gen_int_mode (max_unroll + 1, desc->mode));
   loop->nb_iterations_upper_bound
-    = loop->nb_iterations_upper_bound.udiv (double_int::from_uhwi (max_unroll
-								   + 1),
-					    TRUNC_DIV_EXPR);
+    = wi::udiv_trunc (loop->nb_iterations_upper_bound, max_unroll + 1);
   if (loop->any_estimate)
     loop->nb_iterations_estimate
-      = loop->nb_iterations_estimate.udiv (double_int::from_uhwi (max_unroll
-							          + 1),
-				           TRUNC_DIV_EXPR);
+      = wi::udiv_trunc (loop->nb_iterations_estimate, max_unroll + 1);
   if (exit_at_end)
     {
       desc->niter_expr =
@@ -1316,7 +1306,7 @@  unroll_loop_runtime_iterations (struct loop *loop)
       desc->noloop_assumptions = NULL_RTX;
       --loop->nb_iterations_upper_bound;
       if (loop->any_estimate
-	  && loop->nb_iterations_estimate != double_int_zero)
+	  && loop->nb_iterations_estimate != 0)
 	--loop->nb_iterations_estimate;
       else
 	loop->any_estimate = false;
@@ -1334,7 +1324,7 @@  static void
 decide_peel_simple (struct loop *loop, int flags)
 {
   unsigned npeel;
-  double_int iterations;
+  widest_int iterations;
 
   if (!(flags & UAP_PEEL))
     {
@@ -1378,7 +1368,8 @@  decide_peel_simple (struct loop *loop, int flags)
   /* If we have realistic estimate on number of iterations, use it.  */
   if (get_estimated_loop_iterations (loop, &iterations))
     {
-      if (double_int::from_shwi (npeel).ule (iterations))
+      /* TODO: unsigned/signed confusion */
+      if (wi::leu_p (npeel, iterations))
 	{
 	  if (dump_file)
 	    {
@@ -1395,7 +1386,7 @@  decide_peel_simple (struct loop *loop, int flags)
   /* If we have small enough bound on iterations, we can still peel (completely
      unroll).  */
   else if (get_max_loop_iterations (loop, &iterations)
-           && iterations.ult (double_int::from_shwi (npeel)))
+           && wi::ltu_p (iterations, npeel))
     npeel = iterations.to_shwi () + 1;
   else
     {
@@ -1489,7 +1480,7 @@  decide_unroll_stupid (struct loop *loop, int flags)
 {
   unsigned nunroll, nunroll_by_av, i;
   struct niter_desc *desc;
-  double_int iterations;
+  widest_int iterations;
 
   if (!(flags & UAP_UNROLL_ALL))
     {
@@ -1546,7 +1537,7 @@  decide_unroll_stupid (struct loop *loop, int flags)
   /* Check whether the loop rolls.  */
   if ((get_estimated_loop_iterations (loop, &iterations)
        || get_max_loop_iterations (loop, &iterations))
-      && iterations.ult (double_int::from_shwi (2 * nunroll)))
+      && wi::ltu_p (iterations, 2 * nunroll))
     {
       if (dump_file)
 	fprintf (dump_file, ";; Not unrolling loop, doesn't roll\n");