This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix for PR19590: IVs with the same evolution not eliminated


Hi,

While I'm still at the bugs' chapter, here is a long due patch for this
missed optimization PR.  We just make use of the info that scev
provides and the magic happens.

I'm bootstrapping and testing the attached patch on i686-linux,
okay for trunk once it finishes?

Thanks,
Sebastian
2007-06-21  Sebastian Pop  <sebpop@gmail.com>

	PR tree-optimization/19590
	* tree-vrp.c (adjust_range_with_scev): Set the range when the result
	of scev is a constant.

Index: tree-vrp.c
===================================================================
--- tree-vrp.c	(revision 125915)
+++ tree-vrp.c	(working copy)
@@ -2635,6 +2635,14 @@ adjust_range_with_scev (value_range_t *v
     return;
 
   chrec = instantiate_parameters (loop, analyze_scalar_evolution (loop, var));
+
+  /* Like in PR19590, scev can return a constant function.  */
+  if (is_gimple_min_invariant (chrec))
+    {
+      set_value_range (vr, VR_RANGE, chrec, chrec, vr->equiv);
+      return;
+    }
+
   if (TREE_CODE (chrec) != POLYNOMIAL_CHREC)
     return;
 
Index: testsuite/gcc.dg/tree-ssa/pr19590.c
===================================================================
--- testsuite/gcc.dg/tree-ssa/pr19590.c	(revision 0)
+++ testsuite/gcc.dg/tree-ssa/pr19590.c	(revision 0)
@@ -0,0 +1,37 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ivopts" } */
+
+void vnum_test8(int *data) 
+{ 
+  int i; 
+  int stop = data[3]; 
+  int m = data[4]; 
+  int n = m; 
+  for (i=1; i<stop; i++) { 
+    int k = data[2]; 
+    data[k] = 2; 
+    data[0] = m - n; 
+    k = data[1]; 
+    m = m + k; 
+    n = n + k; 
+  } 
+} 
+
+/* Using the SCEV analysis, this loop should be transformed to:
+
+   | void vnum_result8(int *data) 
+   |{ 
+   |  int i; 
+   |  int stop = data[3]; 
+   |  for (i=1; i<stop; i++) { 
+   |    int k = data[2]; 
+   |    data[k] = 2; 
+   |    data[0] = 0; 
+   |  } 
+   |}
+
+*/
+
+/* { dg-final { scan-tree-dump-times "= 0;" 1 "ivopts"} } */
+/* { dg-final { scan-tree-dump-times "= 2;" 1 "ivopts"} } */
+/* { dg-final { cleanup-tree-dump "ivopts" } }  */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]