2013-11-19 Richard Biener <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 19 Nov 2013 09:21:07 +0000 (09:21 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 19 Nov 2013 09:21:07 +0000 (09:21 +0000)
PR tree-optimization/57517
* tree-predcom.c (combinable_refs_p): Verify the combination
is always executed when the refs are.

* gfortran.fortran-torture/compile/pr57517.f90: New testcase.
* gcc.dg/torture/pr57517.c: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@205010 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr57517.c [new file with mode: 0644]
gcc/testsuite/gfortran.fortran-torture/compile/pr57517.f90 [new file with mode: 0644]
gcc/tree-predcom.c

index d759d4c..65601e8 100644 (file)
@@ -1,3 +1,9 @@
+2013-11-19  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/57517
+       * tree-predcom.c (combinable_refs_p): Verify the combination
+       is always executed when the refs are.
+
 2013-11-19  Jeff Law  <law@redhat.com>
 
        * tree-ssa-threadupdate.c: Include ssa-iterators.h
index 7e28844..06e0bf5 100644 (file)
@@ -1,3 +1,9 @@
+2013-11-19  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/57517
+       * gfortran.fortran-torture/compile/pr57517.f90: New testcase.
+       * gcc.dg/torture/pr57517.c: Likewise.
+
 2013-11-19  Jan Hubicka  <jh@suse.cz>
 
        * gcc.target/i386/memcpy-3.c: New testcase.
diff --git a/gcc/testsuite/gcc.dg/torture/pr57517.c b/gcc/testsuite/gcc.dg/torture/pr57517.c
new file mode 100644 (file)
index 0000000..2422d8e
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+
+int x[1024], y[1024], z[1024], w[1024];
+void foo (void)
+{
+  int i;
+  for (i = 1; i < 1024; ++i)
+    {
+      int a = x[i];
+      int b = y[i];
+      int c = x[i-1];
+      int d = y[i-1];
+      if (w[i])
+       z[i] = (a + b) + (c + d);
+    }
+}
diff --git a/gcc/testsuite/gfortran.fortran-torture/compile/pr57517.f90 b/gcc/testsuite/gfortran.fortran-torture/compile/pr57517.f90
new file mode 100644 (file)
index 0000000..f32698a
--- /dev/null
@@ -0,0 +1,13 @@
+SUBROUTINE cal_helicity (uh, ph, phb, wavg, ims, ime, its, ite)
+  INTEGER, INTENT( IN ) :: ims, ime, its, ite
+  REAL, DIMENSION( ims:ime), INTENT( IN ) :: ph, phb, wavg
+  REAL, DIMENSION( ims:ime), INTENT( INOUT ) :: uh
+  INTEGER :: i
+  REAL :: zu
+  DO i = its, ite
+    zu =  (ph(i ) + phb(i)) + (ph(i-1) + phb(i-1))
+    IF (wavg(i) .GT. 0) THEN
+      uh(i) = uh(i) + zu 
+    ENDIF
+  END DO
+END SUBROUTINE cal_helicity
index 77a15ab..a43d19b 100644 (file)
@@ -2035,7 +2035,11 @@ combinable_refs_p (dref r1, dref r2,
 
   stmt = find_common_use_stmt (&name1, &name2);
 
-  if (!stmt)
+  if (!stmt
+      /* A simple post-dominance check - make sure the combination
+         is executed under the same condition as the references.  */
+      || (gimple_bb (stmt) != gimple_bb (r1->stmt)
+         && gimple_bb (stmt) != gimple_bb (r2->stmt)))
     return false;
 
   acode = gimple_assign_rhs_code (stmt);