[2/4][PATCH] Fix PR87979

Roman Zhuykov zhroma@ispras.ru
Tue Apr 16 12:05:00 GMT 2019


We divide by zero when we try to schedule loop body in zero cycles.  
Both res_mii and rec_mii estimations equals zero.  We have to start with 
one cycle in this situation.

Same failure happens in the following tests on ia64 platform with 
-fmodulo-sched enabled (with any of -O1, -O2, -Os):
gcc.dg/torture/pr82762.c
gcc.c-torture/execute/20170419-1.c

I’ve described patch testing in cover letter. Ok for trunk?

gcc/ChangeLog:

2019-04-08  Roman Zhuykov  <zhroma@ispras.ru>

	PR rtl-optimization/87979
	* modulo-sched.c (sms_schedule): Start ii value "mii" should
	not equal zero.

gcc/testsuite/ChangeLog:

2019-04-08  Roman Zhuykov  <zhroma@ispras.ru>

	PR rtl-optimization/87979
	* gcc.dg/pr87979.c: New test.


diff --git a/gcc/modulo-sched.c b/gcc/modulo-sched.c
--- a/gcc/modulo-sched.c
+++ b/gcc/modulo-sched.c
@@ -1602,6 +1602,7 @@ sms_schedule (void)
        mii = 1; /* Need to pass some estimate of mii.  */
        rec_mii = sms_order_nodes (g, mii, node_order, &max_asap);
        mii = MAX (res_MII (g), rec_mii);
+      mii = MAX (mii, 1);
        maxii = MAX (max_asap, MAXII_FACTOR * mii);

        if (dump_file)
diff --git a/gcc/testsuite/gcc.dg/pr87979.c 
b/gcc/testsuite/gcc.dg/pr87979.c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr87979.c
@@ -0,0 +1,11 @@
+/* PR rtl-optimization/87979 */
+/* { dg-do compile } */
+/* { dg-options "-Os -fmodulo-sched -fno-tree-loop-im" } */
+/* { dg-additional-options "-march=z196" { target { s390*-*-* } } } */
+
+void foo(void)
+{
+  static int m;
+  for (int i = 0; i < 10; ++i)
+    m++;
+}



More information about the Gcc-patches mailing list