diff mbox series

Fix PR82849 (ICE in modulo scheduling)

Message ID 20171119144611.GA20392@kam.mff.cuni.cz
State New
Headers show
Series Fix PR82849 (ICE in modulo scheduling) | expand

Commit Message

Jan Hubicka Nov. 19, 2017, 2:46 p.m. UTC
Hi,
my understanding of the code is that trip_count is trying to estimate number
of iterations when counts are available and disable modulo scheduler for
loops with too few iterations.
We now have get_estimated_loop_iterations_int and get_max_loop_iterations_int
which keeps information detected upstream and so we should use i there.

I tested the patch very lightly only on the testcase in question as I am not
sure when and how modulo sched is used.

Seems sane? What are the code size impacts of modulo scheduling?

Honza

	PR 82849
	* modulo-sched.c (sms_schedule): Use get_estimated_loop_iterations_int
	and get_max_loop_iterations_int.

Comments

Jeff Law Nov. 21, 2017, 5:29 p.m. UTC | #1
On 11/19/2017 07:46 AM, Jan Hubicka wrote:
> Hi,
> my understanding of the code is that trip_count is trying to estimate number
> of iterations when counts are available and disable modulo scheduler for
> loops with too few iterations.
That's my reading as well.

> We now have get_estimated_loop_iterations_int and get_max_loop_iterations_int
> which keeps information detected upstream and so we should use i there.
> 
> I tested the patch very lightly only on the testcase in question as I am not
> sure when and how modulo sched is used.
I don't think it's enabled anywhere by default.  IIRC it was primarily
used on ia64, though my recollection is also that they group that did
the work also saw good gains on ppc.

I still think we need to do some kind of evaluation about whether or not
to keep that code.  If it's not being used, then it's just a maintenance
burden.

> 
> Seems sane? What are the code size impacts of modulo scheduling?
Given it's a software pipelining algorithm I'd expect it expands code,
consistently :-)  But it's probably less than loop unrolling in general.


> 
> Honza
> 
> 	PR 82849
> 	* modulo-sched.c (sms_schedule): Use get_estimated_loop_iterations_int
> 	and get_max_loop_iterations_int.
Seems reasoanble.  I'd go with it.

jeff
diff mbox series

Patch

Index: modulo-sched.c
===================================================================
--- modulo-sched.c	(revision 254929)
+++ modulo-sched.c	(working copy)
@@ -1346,7 +1346,7 @@  sms_schedule (void)
   struct loop *loop;
   basic_block condition_bb = NULL;
   edge latch_edge;
-  gcov_type trip_count = 0;
+  HOST_WIDE_INT trip_count, max_trip_count;
 
   loop_optimizer_init (LOOPS_HAVE_PREHEADERS
 		       | LOOPS_HAVE_RECORDED_EXITS);
@@ -1422,9 +1422,8 @@  sms_schedule (void)
       get_ebb_head_tail (bb, bb, &head, &tail);
       latch_edge = loop_latch_edge (loop);
       gcc_assert (single_exit (loop));
-      if (single_exit (loop)->count () > profile_count::zero ())
-	trip_count = latch_edge->count ().to_gcov_type ()
-		     / single_exit (loop)->count ().to_gcov_type ();
+      trip_count = get_estimated_loop_iterations_int (loop);
+      max_trip_count = get_max_loop_iterations_int (loop);
 
       /* Perform SMS only on loops that their average count is above threshold.  */
 
@@ -1444,8 +1443,8 @@  sms_schedule (void)
 	             	   (int64_t) bb->count.to_gcov_type ());
 	      	  fprintf (dump_file, "\n");
                   fprintf (dump_file, "SMS trip-count ");
-                  fprintf (dump_file, "%" PRId64,
-                           (int64_t) trip_count);
+                  fprintf (dump_file, "%" PRId64 "max %" PRId64,
+                           (int64_t) trip_count, (int64_t) max_trip_count);
                   fprintf (dump_file, "\n");
 	      	  fprintf (dump_file, "SMS profile-sum-max ");
 	      	  fprintf (dump_file, "%" PRId64,
@@ -1552,9 +1551,8 @@  sms_schedule (void)
 
       latch_edge = loop_latch_edge (loop);
       gcc_assert (single_exit (loop));
-      if (single_exit (loop)->count ()> profile_count::zero ())
-	trip_count = latch_edge->count ().to_gcov_type ()
-		     / single_exit (loop)->count ().to_gcov_type ();
+      trip_count = get_estimated_loop_iterations_int (loop);
+      max_trip_count = get_max_loop_iterations_int (loop);
 
       if (dump_file)
 	{
@@ -1648,7 +1646,8 @@  sms_schedule (void)
 	     we let the scheduling passes do the job in this case.  */
 	  if (stage_count < PARAM_VALUE (PARAM_SMS_MIN_SC)
 	      || (count_init && (loop_count <= stage_count))
-	      || (flag_branch_probabilities && (trip_count <= stage_count)))
+	      || (max_trip_count >= 0 && max_trip_count <= stage_count)
+	      || (trip_count >= 0 && trip_count <= stage_count))
 	    {
 	      if (dump_file)
 		{
@@ -1657,7 +1656,8 @@  sms_schedule (void)
 			   " loop-count=", stage_count);
 		  fprintf (dump_file, "%" PRId64, loop_count);
 		  fprintf (dump_file, ", trip-count=");
-		  fprintf (dump_file, "%" PRId64, trip_count);
+		  fprintf (dump_file, "%" PRId64 "max %" PRId64,
+			   (int64_t) trip_count, (int64_t) max_trip_count);
 		  fprintf (dump_file, ")\n");
 		}
 	      break;