[PATCH] Fix PR57517

Richard Biener rguenther@suse.de
Tue Nov 19 10:36:00 GMT 2013


This fixes a predcom ICE where it commons a combination of two
loads but with the combination being conditionally executed.
It's not prepared to handle this situation, disabled with
the following.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to
trunk and 4.8 branch for now.

Richard.

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.

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

Index: gcc/tree-predcom.c
===================================================================
*** gcc/tree-predcom.c	(revision 204948)
--- gcc/tree-predcom.c	(working copy)
*************** combinable_refs_p (dref r1, dref r2,
*** 2068,2074 ****
  
    stmt = find_common_use_stmt (&name1, &name2);
  
!   if (!stmt)
      return false;
  
    acode = gimple_assign_rhs_code (stmt);
--- 2068,2078 ----
  
    stmt = find_common_use_stmt (&name1, &name2);
  
!   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);
Index: gcc/testsuite/gfortran.fortran-torture/compile/pr57517.f90
===================================================================
*** gcc/testsuite/gfortran.fortran-torture/compile/pr57517.f90	(revision 0)
--- gcc/testsuite/gfortran.fortran-torture/compile/pr57517.f90	(working copy)
***************
*** 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: gcc/testsuite/gcc.dg/torture/pr57517.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr57517.c	(revision 0)
--- gcc/testsuite/gcc.dg/torture/pr57517.c	(working copy)
***************
*** 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);
+     }
+ }



More information about the Gcc-patches mailing list