diff mbox

Fix PR62217

Message ID alpine.LSU.2.11.1502181043570.28824@zhemvz.fhfr.qr
State New
Headers show

Commit Message

Richard Biener Feb. 18, 2015, 9:45 a.m. UTC
The following patch extends a heuristic in DOM that avoids propagating
copies into IV increments to cover all BIV replacements.  This avoids
the extra loop copy complete peeling produces and would have also
avoided the array bound warning had we not disabled them completely
from VRP2.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2015-02-18  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/62217
	* tree-ssa-dom.c (cprop_operand): Avoid propagating copies
	into BIVs.

	* gcc.dg/tree-ssa/cunroll-11.c: New testcase.
diff mbox

Patch

Index: gcc/tree-ssa-dom.c
===================================================================
--- gcc/tree-ssa-dom.c	(revision 220755)
+++ gcc/tree-ssa-dom.c	(working copy)
@@ -2291,11 +2291,16 @@  cprop_operand (gimple stmt, use_operand_
       if (!may_propagate_copy (op, val))
 	return;
 
-      /* Do not propagate copies into simple IV increment statements.
-         See PR23821 for how this can disturb IV analysis.  */
-      if (TREE_CODE (val) != INTEGER_CST
-	  && simple_iv_increment_p (stmt))
-	return;
+      /* Do not propagate copies into BIVs.
+         See PR23821 and PR62217 for how this can disturb IV and
+	 number of iteration analysis.  */
+      if (TREE_CODE (val) != INTEGER_CST)
+	{
+	  gimple def = SSA_NAME_DEF_STMT (op);
+	  if (gimple_code (def) == GIMPLE_PHI
+	      && gimple_bb (def)->loop_father->header == gimple_bb (def))
+	    return;
+	}
 
       /* Dump details.  */
       if (dump_file && (dump_flags & TDF_DETAILS))
Index: gcc/testsuite/gcc.dg/tree-ssa/cunroll-11.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/cunroll-11.c	(revision 0)
+++ gcc/testsuite/gcc.dg/tree-ssa/cunroll-11.c	(working copy)
@@ -0,0 +1,18 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O3 -Warray-bounds -fdump-tree-cunroll-details" } */
+
+typedef struct { unsigned data; } s1;
+s1 g_x[4];
+
+extern void foo (s1 *x1, s1 *x2, int a, int b)
+{
+  int i;
+  for(i = 0; i < a; i++)
+    if(i == b)
+      g_x[i] = *x1;
+    else
+      g_x[i] = *x2;
+}
+
+/* { dg-final { scan-tree-dump "Loop 1 iterates at most 3 times" "cunroll" } } */
+/* { dg-final { cleanup-tree-dump "cunroll" } } */